-- Reprise des étudiants de Miage Ksar El Kébir (98 étudiants) — généré le 15/10/2026 17:44.
-- Prérequis : creer_centre_ksar_el_kebir.sql, formations_ksar_el_kebir.sql, classes_ksar_el_kebir.sql, puis colonnes_ajoutees_serveur.sql.
-- phpMyAdmin : Importer (fichier) ou onglet SQL. À exécuter UNE SEULE FOIS : si des étudiants K… existent déjà, le script s'arrête sans rien modifier.
SET NAMES utf8mb4;
START TRANSACTION;
-- Garde-fou : erreur 1242 (et arrêt) si la reprise a déjà été faite.
SET @deja := (SELECT n FROM (SELECT 1 n UNION ALL SELECT 2) t WHERE EXISTS (SELECT 1 FROM n_etudiants WHERE etud_matricule IN ('K263601','K263602','K263603','K263604','K263501','K263502','K263503','K263504','K263401','K263402','K263403','K263404','K263405','K263406','K263407','K263801','K263802','K263803','K263301','K263302','K263303','K263304','K263305','K263306','K242103','K242104','K252101','K253602','K253603','K253604','K253605','K253606','K253607','K253608','K253609','K253610','K253611','K253612','K253614','K253502','K253503','K253505','K253506','K253507','K253508','K253509','K253510','K253511','K253512','K253514','K243405','K253401','K253402','K253403','K253404','K253405','K253406','K253407','K253408','K253409','K253410','K253801','K253802','K253803','K253804','K253805','K253806','K253807','K253808','K253809','K253810','K253811','K253813','K253814','K253815','K253816','K253817','K253818','K253819','K253820','K253821','K253823','K253824','K253825','K253301','K253302','K253303','K253304','K253305','K253306','K253307','K253308','K253309','K253310','K253312','K253313','K253315','K253316')));
SET @ksar := (SELECT ct_id FROM n_centres WHERE ct_code = 'KSAR');
-- Erreur volontaire si le centre KSAR n'existe pas encore (exécutez d'abord creer_centre_ksar_el_kebir.sql).
SET @verif := (SELECT n FROM (SELECT 1 n UNION ALL SELECT 2) t WHERE @ksar IS NULL);
SET @site := (SELECT site_id FROM n_sites WHERE site_centre_id = @ksar AND site_est_principal = 1 LIMIT 1);
SET @role_etudiant := (SELECT role_id FROM n_roles WHERE role_code = 'ETUDIANT');

-- ===== K263601 EL KARKRI Bassma
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263601@provisoire', NULL, 'Bassma EL KARKRI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263601@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263601@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL KARKRI', 'Bassma', 'الكركري', 'بسمة', 'F', '2008-08-18', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271352', NULL, 'P141161687', NULL, NULL, NULL, NULL, 'k263601@provisoire', '0615058916', '0615058916', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:32', '2026-10-15 17:16:32', '2026-10-15 16:30:01', '2026-10-15 17:16:36', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2026', '2026-10-15 17:16:33', '2026-10-15 17:16:33');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:33', '2026-10-15 16:16:33', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263601 (reprise).', NULL, '2026-10-15 17:16:36', '2026-10-15 16:16:36', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263601', 'MME', 'EL KARKRI', 'Bassma', 'الكركري', 'بسمة', 'F', '2008-08-18', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271352', NULL, 'P141161687', NULL, NULL, NULL, 'k263601@provisoire', '0615058916', '0', @u, '2026-10-15 17:16:34', '2026-10-15 17:30:00');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-07-14', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263601', '2026-10-15 17:16:35', '2026-10-15 17:16:35');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263601', '2026-07-14', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:35', '2026-10-15 17:16:35');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:35', '2026-10-15 16:16:36', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:36', '2026-10-15 17:16:36', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:36', '2026-10-15 17:16:36', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:36', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:36', '2026-10-15 17:16:36', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:36', '2026-10-15 17:16:36', '1', 'Annuité 2026-2027');

-- ===== K263602 EL BAHI Wissal
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263602@provisoire', NULL, 'Wissal EL BAHI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263602@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263602@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL BAHI', 'Wissal', 'البهي', 'وصال', 'F', NULL, (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB246122', NULL, NULL, NULL, NULL, NULL, NULL, 'k263602@provisoire', NULL, NULL, NULL, NULL, 'fr', NULL, NULL, NULL, NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:36', '2026-10-15 17:16:36', '2026-10-15 16:30:01', '2026-10-15 17:16:36', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2026-10-15 17:16:36', '2026-10-15 17:16:36');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:36', '2026-10-15 16:16:36', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263602 (reprise).', NULL, '2026-10-15 17:16:36', '2026-10-15 16:16:36', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263602', 'MME', 'EL BAHI', 'Wissal', 'البهي', 'وصال', 'F', NULL, (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB246122', NULL, NULL, NULL, NULL, NULL, 'k263602@provisoire', NULL, '0', @u, '2026-10-15 17:16:36', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', NULL, NULL, NULL, NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263602', '2026-10-15 17:16:36', '2026-10-15 17:16:36');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263602', '2026-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:36', '2026-10-15 17:16:36');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:36', '2026-10-15 16:16:36', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:36', '2026-10-15 17:16:36', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:36', '2026-10-15 17:16:36', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:36', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:36', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:36', '2026-10-15 17:16:36', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:36', '2026-10-15 17:16:36', '1', 'Annuité 2026-2027');

-- ===== K263603 SALMOUN Wiam
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263603@provisoire', NULL, 'Wiam SALMOUN', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263603@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263603@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'SALMOUN', 'Wiam', 'سلمون', 'وئام', 'F', '2005-05-27', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271948', NULL, 'P134045099', NULL, NULL, NULL, NULL, 'k263603@provisoire', '0767549410', '0767549410', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:36', '2026-10-15 17:16:36', '2026-10-15 16:30:01', '2026-10-15 17:16:37', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:36', '2026-10-15 17:16:36');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:36', '2026-10-15 16:16:36', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263603 (reprise).', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263603', 'MME', 'SALMOUN', 'Wiam', 'سلمون', 'وئام', 'F', '2005-05-27', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271948', NULL, 'P134045099', NULL, NULL, NULL, 'k263603@provisoire', '0767549410', '0', @u, '2026-10-15 17:16:37', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-08', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263603', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263603', '2026-09-08', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');

-- ===== K263604 NAJHCHA Sohaib
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263604@provisoire', NULL, 'Sohaib NAJHCHA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263604@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263604@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'NAJHCHA', 'Sohaib', 'نجحشة', 'صهيب', 'M', '2007-01-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB268499', NULL, 'P135056198', NULL, NULL, NULL, NULL, 'k263604@provisoire', '0712252701', '0712252701', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', '2026-10-15 16:30:01', '2026-10-15 17:16:37', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263604 (reprise).', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263604', 'M', 'NAJHCHA', 'Sohaib', 'نجحشة', 'صهيب', 'M', '2007-01-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB268499', NULL, 'P135056198', NULL, NULL, NULL, 'k263604@provisoire', '0712252701', '0', @u, '2026-10-15 17:16:37', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-09', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263604', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263604', '2026-09-09', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');

-- ===== K263501 EN-NESRAOUI Maryem
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263501@provisoire', NULL, 'Maryem EN-NESRAOUI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263501@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263501@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EN-NESRAOUI', 'Maryem', 'النسراوي', 'مريم', 'F', '2003-07-12', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Arbaoua' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB285996', NULL, 'E131066077', NULL, NULL, NULL, NULL, 'k263501@provisoire', '0666876035', '0666876035', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2021', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', '2026-10-15 16:30:01', '2026-10-15 17:16:37', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2021', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263501 (reprise).', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263501', 'MME', 'EN-NESRAOUI', 'Maryem', 'النسراوي', 'مريم', 'F', '2003-07-12', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Arbaoua' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB285996', NULL, 'E131066077', NULL, NULL, NULL, 'k263501@provisoire', '0666876035', '0', @u, '2026-10-15 17:16:37', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-07-09', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2021', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263501', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263501', '2026-07-09', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');

-- ===== K263502 BEN EL ACH-HAB Hiba
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263502@provisoire', NULL, 'Hiba BEN EL ACH-HAB', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263502@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263502@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'BEN EL ACH-HAB', 'Hiba', 'بن الأشهب', 'هبة', 'F', '2005-05-13', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272494', NULL, 'P136086141', NULL, NULL, NULL, NULL, 'k263502@provisoire', NULL, NULL, NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', '2026-10-15 16:30:01', '2026-10-15 17:16:37', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2026', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263502 (reprise).', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263502', 'MME', 'BEN EL ACH-HAB', 'Hiba', 'بن الأشهب', 'هبة', 'F', '2005-05-13', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272494', NULL, 'P136086141', NULL, NULL, NULL, 'k263502@provisoire', NULL, '0', @u, '2026-10-15 17:16:37', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-07', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263502', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263502', '2026-09-07', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');

-- ===== K263503 CHAGHRNI Zouhra
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263503@provisoire', NULL, 'Zouhra CHAGHRNI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263503@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263503@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'CHAGHRNI', 'Zouhra', 'الشغرني', 'زهرة', 'F', '2004-12-22', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB257725', NULL, 'P110019929', NULL, NULL, NULL, NULL, 'k263503@provisoire', NULL, NULL, NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', '2026-10-15 16:30:01', '2026-10-15 17:16:37', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263503 (reprise).', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263503', 'MME', 'CHAGHRNI', 'Zouhra', 'الشغرني', 'زهرة', 'F', '2004-12-22', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB257725', NULL, 'P110019929', NULL, NULL, NULL, 'k263503@provisoire', NULL, '0', @u, '2026-10-15 17:16:37', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-07', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263503', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263503', '2026-09-07', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');

-- ===== K263504 SELLOUTI Abderrahmane
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263504@provisoire', NULL, 'Abderrahmane SELLOUTI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263504@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263504@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'SELLOUTI', 'Abderrahmane', 'السلوتي', 'عبد الرحمان', 'M', NULL, NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272427', NULL, 'P140162360', NULL, NULL, NULL, NULL, 'k263504@provisoire', '0643520205', '0643520205', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', '2026-10-15 16:30:01', '2026-10-15 17:16:37', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2026', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263504 (reprise).', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263504', 'M', 'SELLOUTI', 'Abderrahmane', 'السلوتي', 'عبد الرحمان', 'M', NULL, NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272427', NULL, 'P140162360', NULL, NULL, NULL, 'k263504@provisoire', '0643520205', '0', @u, '2026-10-15 17:16:37', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-08', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263504', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263504', '2026-09-08', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');

-- ===== K263401 TOUHAMI Haitam
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263401@provisoire', NULL, 'Haitam TOUHAMI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263401@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263401@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'TOUHAMI', 'Haitam', 'التهامي', 'هيثم', 'M', '2003-08-09', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB250016', NULL, 'P149063519', NULL, NULL, NULL, NULL, 'k263401@provisoire', '0628703495', '0628703495', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2021', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', '2026-10-15 16:30:01', '2026-10-15 17:16:38', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2021', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263401 (reprise).', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263401', 'M', 'TOUHAMI', 'Haitam', 'التهامي', 'هيثم', 'M', '2003-08-09', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB250016', NULL, 'P149063519', NULL, NULL, NULL, 'k263401@provisoire', '0628703495', '0', @u, '2026-10-15 17:16:37', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-08-27', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2021', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263401', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263401', '2026-08-27', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:37', '2026-10-15 17:16:37');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:37', '2026-10-15 16:16:37', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:37', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:37', '2026-10-15 17:16:37', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:37', '2026-10-15 17:16:37', '1', 'Annuité 2026-2027');

-- ===== K263402 CHANIA Bousselham
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263402@provisoire', NULL, 'Bousselham CHANIA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263402@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263402@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'CHANIA', 'Bousselham', 'شنية', 'بوسلهام', 'M', '2005-01-21', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Moulay Bousselham' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB315444', NULL, 'E142172296', NULL, NULL, NULL, NULL, 'k263402@provisoire', '0638995132', '0638995132', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', '2026-10-15 16:30:01', '2026-10-15 17:16:38', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263402 (reprise).', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263402', 'M', 'CHANIA', 'Bousselham', 'شنية', 'بوسلهام', 'M', '2005-01-21', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Moulay Bousselham' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB315444', NULL, 'E142172296', NULL, NULL, NULL, 'k263402@provisoire', '0638995132', '0', @u, '2026-10-15 17:16:38', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-08-31', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263402', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263402', '2026-08-31', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');

-- ===== K263403 TAHIRI Malak
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263403@provisoire', NULL, 'Malak TAHIRI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263403@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263403@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'TAHIRI', 'Malak', 'الطاهري', 'ملاك', 'F', '2009-01-02', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'ES855736', NULL, 'P145135413', NULL, NULL, NULL, NULL, 'k263403@provisoire', '0721549838', '0721549838', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', '2026-10-15 16:30:01', '2026-10-15 17:16:38', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2026', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263403 (reprise).', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263403', 'MME', 'TAHIRI', 'Malak', 'الطاهري', 'ملاك', 'F', '2009-01-02', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'ES855736', NULL, 'P145135413', NULL, NULL, NULL, 'k263403@provisoire', '0721549838', '0', @u, '2026-10-15 17:16:38', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263403', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263403', '2026-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');

-- ===== K263404 NEJJAR Hamza
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263404@provisoire', NULL, 'Hamza NEJJAR', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263404@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263404@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'NEJJAR', 'Hamza', 'النجار', 'حمزة', 'M', '2008-08-11', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Kenitra' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB332061', NULL, 'E142224200', NULL, NULL, NULL, NULL, 'k263404@provisoire', '06746089400655481074', '06746089400655481074', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', '2026-10-15 16:30:01', '2026-10-15 17:16:38', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2026', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263404 (reprise).', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263404', 'M', 'NEJJAR', 'Hamza', 'النجار', 'حمزة', 'M', '2008-08-11', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Kenitra' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB332061', NULL, 'E142224200', NULL, NULL, NULL, 'k263404@provisoire', '06746089400655481074', '0', @u, '2026-10-15 17:16:38', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-03', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263404', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263404', '2026-09-03', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');

-- ===== K263405 YEMLAHI Marouan
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263405@provisoire', NULL, 'Marouan YEMLAHI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263405@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263405@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'YEMLAHI', 'Marouan', 'اليملاحي', 'مروان', 'M', '2008-03-21', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB284130', NULL, 'P143179455', NULL, NULL, NULL, NULL, 'k263405@provisoire', '0728224117', '0728224117', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', '2026-10-15 16:30:01', '2026-10-15 17:16:38', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2026', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263405 (reprise).', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263405', 'M', 'YEMLAHI', 'Marouan', 'اليملاحي', 'مروان', 'M', '2008-03-21', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB284130', NULL, 'P143179455', NULL, NULL, NULL, 'k263405@provisoire', '0728224117', '0', @u, '2026-10-15 17:16:38', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-08', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263405', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263405', '2026-09-08', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');

-- ===== K263406 EL HARRAK Taha
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263406@provisoire', NULL, 'Taha EL HARRAK', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263406@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263406@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL HARRAK', 'Taha', 'الحراق', 'طه', 'M', '2006-08-18', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB265100', NULL, 'P131043489', NULL, NULL, NULL, NULL, 'k263406@provisoire', '0684472045', '0684472045', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', '2026-10-15 16:30:01', '2026-10-15 17:16:38', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263406 (reprise).', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263406', 'M', 'EL HARRAK', 'Taha', 'الحراق', 'طه', 'M', '2006-08-18', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB265100', NULL, 'P131043489', NULL, NULL, NULL, 'k263406@provisoire', '0684472045', '0', @u, '2026-10-15 17:16:38', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-08', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263406', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263406', '2026-09-08', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');

-- ===== K263407 ZOUININA Nassar
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263407@provisoire', NULL, 'Nassar ZOUININA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263407@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263407@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'ZOUININA', 'Nassar', 'زوينينة', 'نصار', 'M', '2007-12-05', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB269716', NULL, 'P134266835', NULL, NULL, NULL, NULL, 'k263407@provisoire', '0666207182', '0666207182', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', '2026-10-15 16:30:01', '2026-10-15 17:16:38', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263407 (reprise).', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263407', 'M', 'ZOUININA', 'Nassar', 'زوينينة', 'نصار', 'M', '2007-12-05', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB269716', NULL, 'P134266835', NULL, NULL, NULL, 'k263407@provisoire', '0666207182', '0', @u, '2026-10-15 17:16:38', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-10', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263407', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263407', '2026-09-10', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '10000.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '1000.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '1000.00', '2026-11-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '1000.00', '2026-12-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '1000.00', '2027-01-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '1000.00', '2027-02-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '1000.00', '2027-03-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '1000.00', '2027-04-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '1000.00', '2027-05-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '1000.00', '2027-06-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '1000.00', '2027-07-05', '2026-10-15 17:16:38', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:38', '2026-10-15 17:16:38', '1', 'Annuité 2026-2027');

-- ===== K263801 EL GALLOURI Johaina
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263801@provisoire', NULL, 'Johaina EL GALLOURI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263801@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263801@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL GALLOURI', 'Johaina', 'القلوري', 'جهينة', 'F', '2008-09-25', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271475', NULL, 'P147120463', NULL, NULL, NULL, NULL, 'k263801@provisoire', '0635179824', '0635179824', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:38', '2026-10-15 17:16:38', '2026-10-15 16:30:01', '2026-10-15 17:16:39', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2026', '2026-10-15 17:16:38', '2026-10-15 17:16:38');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:03', '2026-10-15 17:44:03', '2026-10-15 16:44:03');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:38', '2026-10-15 16:16:38', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263801 (reprise).', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263801', 'MME', 'EL GALLOURI', 'Johaina', 'القلوري', 'جهينة', 'F', '2008-09-25', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271475', NULL, 'P147120463', NULL, NULL, NULL, 'k263801@provisoire', '0635179824', '0', @u, '2026-10-15 17:16:39', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-07-06', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263801', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263801', '2026-07-06', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');

-- ===== K263802 ZBAKH Mohamed
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263802@provisoire', NULL, 'Mohamed ZBAKH', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263802@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263802@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'ZBAKH', 'Mohamed', 'الزباخ', 'محمد', 'M', '2002-02-03', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB245746', NULL, 'Z224400906', NULL, NULL, NULL, NULL, 'k263802@provisoire', '0770112330', '0770112330', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', '2026-10-15 16:30:01', '2026-10-15 17:16:39', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2022', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263802 (reprise).', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263802', 'M', 'ZBAKH', 'Mohamed', 'الزباخ', 'محمد', 'M', '2002-02-03', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB245746', NULL, 'Z224400906', NULL, NULL, NULL, 'k263802@provisoire', '0770112330', '0', @u, '2026-10-15 17:16:39', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-08-27', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263802', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263802', '2026-08-27', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');

-- ===== K263803 DAGHIRI Ziad
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263803@provisoire', NULL, 'Ziad DAGHIRI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263803@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263803@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'DAGHIRI', 'Ziad', 'الضغيري', 'زياد', 'M', '2009-03-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Marrakech' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'E902389', NULL, 'G146135845', NULL, NULL, NULL, NULL, 'k263803@provisoire', '0661782463', '0661782463', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', '2026-10-15 16:30:01', '2026-10-15 17:16:39', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2026', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263803 (reprise).', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263803', 'M', 'DAGHIRI', 'Ziad', 'الضغيري', 'زياد', 'M', '2009-03-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Marrakech' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'E902389', NULL, 'G146135845', NULL, NULL, NULL, 'k263803@provisoire', '0661782463', '0', @u, '2026-10-15 17:16:39', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263803', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263803', '2026-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');

-- ===== K263301 BOULAHFA Amal
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263301@provisoire', NULL, 'Amal BOULAHFA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263301@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263301@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'BOULAHFA', 'Amal', 'بولحفة', 'أمل', 'F', '1998-01-01', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB225913', NULL, 'Z193200873', NULL, NULL, NULL, NULL, 'k263301@provisoire', '0600110151', '0600110151', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2019', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', '2026-10-15 16:30:01', '2026-10-15 17:16:39', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2019', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263301 (reprise).', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263301', 'MME', 'BOULAHFA', 'Amal', 'بولحفة', 'أمل', 'F', '1998-01-01', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB225913', NULL, 'Z193200873', NULL, NULL, NULL, 'k263301@provisoire', '0600110151', '0', @u, '2026-10-15 17:16:39', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-07-18', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2019', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263301', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263301', '2026-07-18', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');

-- ===== K263302 ATTOU Omar
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263302@provisoire', NULL, 'Omar ATTOU', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263302@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263302@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'ATTOU', 'Omar', 'عطو', 'عمر', 'M', '1998-05-07', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Marrakech' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB221391', NULL, 'P133510257', NULL, NULL, NULL, NULL, 'k263302@provisoire', '0601747075', '0601747075', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2016', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', '2026-10-15 16:30:01', '2026-10-15 17:16:39', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2016', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263302 (reprise).', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263302', 'M', 'ATTOU', 'Omar', 'عطو', 'عمر', 'M', '1998-05-07', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Marrakech' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB221391', NULL, 'P133510257', NULL, NULL, NULL, 'k263302@provisoire', '0601747075', '0', @u, '2026-10-15 17:16:39', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2016', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263302', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263302', '2026-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');

-- ===== K263303 ALILOUCH Hind
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263303@provisoire', NULL, 'Hind ALILOUCH', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263303@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263303@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'ALILOUCH', 'Hind', 'عليلوش', 'هند', 'F', '2005-10-07', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB266000', NULL, 'P120086703', NULL, NULL, NULL, NULL, 'k263303@provisoire', '0604574627', '0604574627', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', '2026-10-15 16:30:01', '2026-10-15 17:16:39', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2023', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263303 (reprise).', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263303', 'MME', 'ALILOUCH', 'Hind', 'عليلوش', 'هند', 'F', '2005-10-07', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB266000', NULL, 'P120086703', NULL, NULL, NULL, 'k263303@provisoire', '0604574627', '0', @u, '2026-10-15 17:16:39', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-02', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263303', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263303', '2026-09-02', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');

-- ===== K263304 MOTAHHIR Mohamed
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263304@provisoire', NULL, 'Mohamed MOTAHHIR', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263304@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263304@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'MOTAHHIR', 'Mohamed', 'مطهر', 'محمد', 'M', '2008-11-24', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB285091', NULL, 'P147154718', NULL, NULL, NULL, NULL, 'k263304@provisoire', '0702738426', '0702738426', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', '2026-10-15 16:30:01', '2026-10-15 17:16:39', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2026', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263304 (reprise).', NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263304', 'M', 'MOTAHHIR', 'Mohamed', 'مطهر', 'محمد', 'M', '2008-11-24', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB285091', NULL, 'P147154718', NULL, NULL, NULL, 'k263304@provisoire', '0702738426', '0', @u, '2026-10-15 17:16:39', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-03', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263304', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263304', '2026-09-03', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:39', '2026-10-15 17:16:39');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:39', '2026-10-15 16:16:39', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:39', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:39', '2026-10-15 17:16:39', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:39', '2026-10-15 17:16:39', '1', 'Annuité 2026-2027');

-- ===== K263305 BOUSKIL Sanae
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263305@provisoire', NULL, 'Sanae BOUSKIL', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263305@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263305@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'BOUSKIL', 'Sanae', 'بوسكيل', 'سناء', 'F', '2007-07-17', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB270057', NULL, 'P147057441', NULL, NULL, NULL, NULL, 'k263305@provisoire', '0708734775', '0708734775', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', '2026-10-15 16:30:01', '2026-10-15 17:16:40', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263305 (reprise).', NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263305', 'MME', 'BOUSKIL', 'Sanae', 'بوسكيل', 'سناء', 'F', '2007-07-17', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB270057', NULL, 'P147057441', NULL, NULL, NULL, 'k263305@provisoire', '0708734775', '0', @u, '2026-10-15 17:16:40', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-07', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263305', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263305', '2026-09-07', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 17:16:40', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 17:16:40', '1', 'Annuité 2026-2027');

-- ===== K263306 CHHAIBI Sanae
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k263306@provisoire', NULL, 'Sanae CHHAIBI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k263306@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k263306@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'CHHAIBI', 'Sanae', 'الشهايبي', 'سناء', 'F', '2007-06-16', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB284132', NULL, 'P141069404', NULL, NULL, NULL, NULL, 'k263306@provisoire', '0704437146', '0704437146', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', '2026-10-15 16:30:01', '2026-10-15 17:16:40', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2026', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K263306 (reprise).', NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K263306', 'MME', 'CHHAIBI', 'Sanae', 'الشهايبي', 'سناء', 'F', '2007-06-16', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB284132', NULL, 'P141069404', NULL, NULL, NULL, 'k263306@provisoire', '0704437146', '0', @u, '2026-10-15 17:16:40', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2026-09-09', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2026', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '263306', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K263306', '2026-09-09', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 17:16:40', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 17:16:40', '1', 'Annuité 2026-2027');

-- ===== K242103 SEMMANE Mohammed
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k242103@provisoire', NULL, 'Mohammed SEMMANE', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k242103@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k242103@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'SEMMANE', 'Mohammed', 'السمان', 'محمد', 'M', '2002-04-04', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB291791', NULL, 'E143071639', NULL, NULL, NULL, NULL, 'k242103@provisoire', '0643696495', '0643696495', NULL, NULL, 'fr', NULL, NULL, NULL, NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DT-GI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DT-GI-25' AND c.classe_abbr = 'T-GI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', '2026-10-15 16:30:01', '2026-10-15 17:16:40', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'ATT-REUSSITE-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'PV_ACCESS' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '0', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'PHOTOS' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '0', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'AUTRE_DIP' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '0', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K242103 (reprise).', NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K242103', 'M', 'SEMMANE', 'Mohammed', 'السمان', 'محمد', 'M', '2002-04-04', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB291791', NULL, 'E143071639', NULL, NULL, NULL, 'k242103@provisoire', '0643696495', '0', @u, '2026-10-15 17:16:40', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DT-GI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', NULL, NULL, NULL, NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '242103', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K242103', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DT-GI-25' AND c.classe_abbr = 'T-GI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K242103', '2025-11-13', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DT-GI-25' AND c.classe_abbr = 'T-GI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '700.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '700.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 17:16:40', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '7000.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '700.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '700.00', '2026-11-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '700.00', '2026-12-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '700.00', '2027-01-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '700.00', '2027-02-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '700.00', '2027-03-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '700.00', '2027-04-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '700.00', '2027-05-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '700.00', '2027-06-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '700.00', '2027-07-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 17:16:40', '1', 'Annuité 2026-2027');

-- ===== K242104 EL ISSAOUI Marouane
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k242104@provisoire', NULL, 'Marouane EL ISSAOUI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k242104@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k242104@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL ISSAOUI', 'Marouane', 'العيساوي', 'مروان', 'M', '2006-03-18', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB269592', NULL, 'P135027546', NULL, NULL, NULL, NULL, 'k242104@provisoire', '0674613836', '0674613836', NULL, NULL, 'fr', NULL, NULL, NULL, NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DT-GI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DT-GI-25' AND c.classe_abbr = 'T-GI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', '2026-10-15 16:30:01', '2026-10-15 17:16:40', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'ATT-REUSSITE-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'PV_ACCESS' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '0', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'PHOTOS' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '0', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'AUTRE_DIP' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '0', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K242104 (reprise).', NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K242104', 'M', 'EL ISSAOUI', 'Marouane', 'العيساوي', 'مروان', 'M', '2006-03-18', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB269592', NULL, 'P135027546', NULL, NULL, NULL, 'k242104@provisoire', '0674613836', '0', @u, '2026-10-15 17:16:40', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DT-GI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', NULL, NULL, NULL, NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '242104', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K242104', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DT-GI-25' AND c.classe_abbr = 'T-GI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K242104', '2025-10-06', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DT-GI-25' AND c.classe_abbr = 'T-GI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '700.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '700.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 17:16:40', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '7000.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '700.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '700.00', '2026-11-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '700.00', '2026-12-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '700.00', '2027-01-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '700.00', '2027-02-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '700.00', '2027-03-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '700.00', '2027-04-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '700.00', '2027-05-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '700.00', '2027-06-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '700.00', '2027-07-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 17:16:40', '1', 'Annuité 2026-2027');

-- ===== K252101 EL MOKHTARY Douae
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'k252101@provisoire', NULL, 'Douae EL MOKHTARY', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'k252101@provisoire');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'k252101@provisoire');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL MOKHTARY', 'Douae', 'المختاري', 'دعاء', 'F', '2004-06-14', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB266094', NULL, 'P120088172', NULL, NULL, NULL, NULL, 'k252101@provisoire', '0619084742', '0619084742', NULL, NULL, 'fr', NULL, NULL, NULL, NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DT-GI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DT-GI-25' AND c.classe_abbr = 'T-GI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', '2026-10-15 16:30:01', '2026-10-15 17:16:40', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'ATT-REUSSITE-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'PV_ACCESS' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '0', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'PHOTOS' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '0', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'AUTRE_DIP' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '0', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K252101 (reprise).', NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K252101', 'MME', 'EL MOKHTARY', 'Douae', 'المختاري', 'دعاء', 'F', '2004-06-14', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB266094', NULL, 'P120088172', NULL, NULL, NULL, 'k252101@provisoire', '0619084742', '0', @u, '2026-10-15 17:16:40', '2026-10-15 17:30:01');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DT-GI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', NULL, NULL, NULL, NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '252101', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K252101', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DT-GI-25' AND c.classe_abbr = 'T-GI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K252101', '2025-09-08', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DT-GI-25' AND c.classe_abbr = 'T-GI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '700.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '700.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 17:16:40', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '7000.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '700.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '700.00', '2026-11-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '700.00', '2026-12-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '700.00', '2027-01-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '700.00', '2027-02-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '700.00', '2027-03-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '700.00', '2027-04-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '700.00', '2027-05-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '700.00', '2027-06-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '700.00', '2027-07-05', '2026-10-15 17:16:40', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:40', '2026-10-15 17:16:40', '1', 'Annuité 2026-2027');

-- ===== K253602 EL BOUTI Dina
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'dinaelbouti2003@gmail.com', NULL, 'Dina EL BOUTI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'dinaelbouti2003@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'dinaelbouti2003@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL BOUTI', 'Dina', 'البوطي', 'دينا', 'F', '2003-04-07', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB256628', NULL, 'P137533756', NULL, NULL, NULL, NULL, 'dinaelbouti2003@gmail.com', '0720980515', '0720980515', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:40', '2026-10-15 17:16:40', '2026-10-15 16:16:41', '2026-10-15 17:16:41', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2023', '2026-10-15 17:16:40', '2026-10-15 17:16:40');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:40', '2026-10-15 16:16:40', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253602 (reprise).', NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253602', 'MME', 'EL BOUTI', 'Dina', 'البوطي', 'دينا', 'F', '2003-04-07', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB256628', NULL, 'P137533756', NULL, NULL, NULL, 'dinaelbouti2003@gmail.com', '0720980515', '0', @u, '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253602', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253602', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253602', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:41', '2026-10-15 17:16:41', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:41', '2026-10-15 17:16:41', '1', 'Annuité 2026-2027');

-- ===== K253603 BARKA Rachid
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'rachidbarka1996@gmail.com', NULL, 'Rachid BARKA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'rachidbarka1996@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'rachidbarka1996@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'BARKA', 'Rachid', 'بركة', 'رشيد', 'M', '1996-08-07', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'FL90357', NULL, 'Z213300097', NULL, NULL, NULL, NULL, 'rachidbarka1996@gmail.com', '0616605770', '0616605770', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2021', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', '2026-10-15 17:16:41', '2026-10-15 17:16:41', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2021', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253603 (reprise).', NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253603', 'M', 'BARKA', 'Rachid', 'بركة', 'رشيد', 'M', '1996-08-07', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'FL90357', NULL, 'Z213300097', NULL, NULL, NULL, 'rachidbarka1996@gmail.com', '0616605770', '0', @u, '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2021', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253603', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253603', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253603', '2025-09-02', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:41', '2026-10-15 17:16:41', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:41', '2026-10-15 17:16:41', '1', 'Annuité 2026-2027');

-- ===== K253604 ZOUFRI Mohamed
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'mohamedzefri93@gmail.com', NULL, 'Mohamed ZOUFRI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'mohamedzefri93@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'mohamedzefri93@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'ZOUFRI', 'Mohamed', 'الزوفري', 'محمد', 'M', '2005-07-18', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB254143', NULL, 'P137049755', NULL, NULL, NULL, NULL, 'mohamedzefri93@gmail.com', '0706741922', '0706741922', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', '2026-10-15 17:16:41', '2026-10-15 17:16:41', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253604 (reprise).', NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253604', 'M', 'ZOUFRI', 'Mohamed', 'الزوفري', 'محمد', 'M', '2005-07-18', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB254143', NULL, 'P137049755', NULL, NULL, NULL, 'mohamedzefri93@gmail.com', '0706741922', '0', @u, '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253604', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253604', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253604', '2025-09-10', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:41', '2026-10-15 17:16:41', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:41', '2026-10-15 17:16:41', '1', 'Annuité 2026-2027');

-- ===== K253605 SALHI Ghizlane
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'salhighizlan730@gmail.com', NULL, 'Ghizlane SALHI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'salhighizlan730@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'salhighizlan730@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'SALHI', 'Ghizlane', 'الصالحي', 'غزلان', 'F', '2000-07-30', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB242084', NULL, 'Z234400072', NULL, NULL, NULL, NULL, 'salhighizlan730@gmail.com', '0657419083', '0657419083', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', '2026-10-15 17:16:41', '2026-10-15 17:16:41', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2023', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253605 (reprise).', NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253605', 'MME', 'SALHI', 'Ghizlane', 'الصالحي', 'غزلان', 'F', '2000-07-30', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB242084', NULL, 'Z234400072', NULL, NULL, NULL, 'salhighizlan730@gmail.com', '0657419083', '0', @u, '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253605', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253605', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253605', '2025-09-11', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:41', '2026-10-15 17:16:41', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:41', '2026-10-15 17:16:41', '1', 'Annuité 2026-2027');

-- ===== K253606 EL OUAZZANI Hasnae
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'hasnaeelouazzani07@gmail.com', NULL, 'Hasnae EL OUAZZANI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'hasnaeelouazzani07@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'hasnaeelouazzani07@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL OUAZZANI', 'Hasnae', 'الوزاني', 'حسناء', 'F', '2006-09-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272091', NULL, 'P139325590', NULL, NULL, NULL, NULL, 'hasnaeelouazzani07@gmail.com', '0724520264', '0724520264', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:41', '2026-10-15 17:16:41', '2026-10-15 16:16:42', '2026-10-15 17:16:42', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:41', '2026-10-15 16:16:41', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253606 (reprise).', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253606', 'MME', 'EL OUAZZANI', 'Hasnae', 'الوزاني', 'حسناء', 'F', '2006-09-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272091', NULL, 'P139325590', NULL, NULL, NULL, 'hasnaeelouazzani07@gmail.com', '0724520264', '0', @u, '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253606', '2026-10-15 17:16:41', '2026-10-15 17:16:41');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253606', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253606', '2025-09-11', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');

-- ===== K253607 HILALI Aya
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'ayaelhilali2006rihab@gamil.com', NULL, 'Aya HILALI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'ayaelhilali2006rihab@gamil.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'ayaelhilali2006rihab@gamil.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'HILALI', 'Aya', 'الهلالي', 'آية', 'F', '2006-03-15', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB273103', NULL, 'P145000258', NULL, NULL, NULL, NULL, 'ayaelhilali2006rihab@gamil.com', '0687105852', '0687105852', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253607 (reprise).', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253607', 'MME', 'HILALI', 'Aya', 'الهلالي', 'آية', 'F', '2006-03-15', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB273103', NULL, 'P145000258', NULL, NULL, NULL, 'ayaelhilali2006rihab@gamil.com', '0687105852', '0', @u, '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253607', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253607', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253607', '2025-09-11', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');

-- ===== K253608 EL AKHAL Aya
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'ayaelakhal61@gmail.com', NULL, 'Aya EL AKHAL', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'ayaelakhal61@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'ayaelakhal61@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL AKHAL', 'Aya', 'الأكحل', 'آية', 'F', '2005-04-21', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB263793', NULL, 'P142028350', NULL, NULL, NULL, NULL, 'ayaelakhal61@gmail.com', '0714976329', '0714976329', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2023', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253608 (reprise).', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253608', 'MME', 'EL AKHAL', 'Aya', 'الأكحل', 'آية', 'F', '2005-04-21', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB263793', NULL, 'P142028350', NULL, NULL, NULL, 'ayaelakhal61@gmail.com', '0714976329', '0', @u, '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253608', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253608', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253608', '2025-09-17', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');

-- ===== K253609 EL AHMADI Aya
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'ayaelahmadi12@gmail.com', NULL, 'Aya EL AHMADI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'ayaelahmadi12@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'ayaelahmadi12@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL AHMADI', 'Aya', 'الأحمدي', 'آية', 'F', '2007-08-16', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB277805', NULL, 'P141042634', NULL, NULL, NULL, NULL, 'ayaelahmadi12@gmail.com', '0690412204', '0690412204', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253609 (reprise).', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253609', 'MME', 'EL AHMADI', 'Aya', 'الأحمدي', 'آية', 'F', '2007-08-16', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB277805', NULL, 'P141042634', NULL, NULL, NULL, 'ayaelahmadi12@gmail.com', '0690412204', '0', @u, '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253609', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253609', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253609', '2025-09-22', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');

-- ===== K253610 EL AIDI Samia
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'samiaelaidi830@gmail.com', NULL, 'Samia EL AIDI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'samiaelaidi830@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'samiaelaidi830@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL AIDI', 'Samia', 'العيدي', 'سامية', 'F', '2006-02-10', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB264101', NULL, 'P120086755', NULL, NULL, NULL, NULL, 'samiaelaidi830@gmail.com', '0640410248', '0640410248', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2023', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253610 (reprise).', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253610', 'MME', 'EL AIDI', 'Samia', 'العيدي', 'سامية', 'F', '2006-02-10', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB264101', NULL, 'P120086755', NULL, NULL, NULL, 'samiaelaidi830@gmail.com', '0640410248', '0', @u, '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253610', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253610', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253610', '2025-09-22', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');

-- ===== K253611 BENLHAJ Amine
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'aminebenlhaj4380@gmail.com', NULL, 'Amine BENLHAJ', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'aminebenlhaj4380@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'aminebenlhaj4380@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'BENLHAJ', 'Amine', 'بن الحاج', 'أمين', 'M', '2004-10-31', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ifrane' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB279073', NULL, 'P148179101', NULL, NULL, NULL, NULL, 'aminebenlhaj4380@gmail.com', '0706897470', '0706897470', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253611 (reprise).', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253611', 'M', 'BENLHAJ', 'Amine', 'بن الحاج', 'أمين', 'M', '2004-10-31', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ifrane' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB279073', NULL, 'P148179101', NULL, NULL, NULL, 'aminebenlhaj4380@gmail.com', '0706897470', '0', @u, '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253611', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253611', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253611', '2025-09-30', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');

-- ===== K253612 BENLAABID Nihad
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'benlaabidnihad@gmail.com', NULL, 'Nihad BENLAABID', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'benlaabidnihad@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'benlaabidnihad@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'BENLAABID', 'Nihad', 'بن العبيد', 'نهاد', 'F', '2005-12-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Sidi Kacem' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB324543', NULL, 'E130023819', NULL, NULL, NULL, NULL, 'benlaabidnihad@gmail.com', '0693987790', '0693987790', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253612 (reprise).', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253612', 'MME', 'BENLAABID', 'Nihad', 'بن العبيد', 'نهاد', 'F', '2005-12-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Sidi Kacem' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB324543', NULL, 'E130023819', NULL, NULL, NULL, 'benlaabidnihad@gmail.com', '0693987790', '0', @u, '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253612', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253612', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253612', '2025-10-02', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');

-- ===== K253614 BOUKBIB Bouchra
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'bouchraboukbib@gmail.com', NULL, 'Bouchra BOUKBIB', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'bouchraboukbib@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'bouchraboukbib@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'BOUKBIB', 'Bouchra', 'بوكبيب', 'بشرى', 'F', '2004-11-07', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB248282', NULL, 'P110019944', NULL, NULL, NULL, NULL, 'bouchraboukbib@gmail.com', '0687833468', '0687833468', NULL, NULL, 'fr', NULL, NULL, NULL, NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253614 (reprise).', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253614', 'MME', 'BOUKBIB', 'Bouchra', 'بوكبيب', 'بشرى', 'F', '2004-11-07', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB248282', NULL, 'P110019944', NULL, NULL, NULL, 'bouchraboukbib@gmail.com', '0687833468', '0', @u, '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', NULL, NULL, NULL, NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253614', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253614', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253614', '2025-10-22', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:42', '2026-10-15 17:16:42', '1', 'Annuité 2026-2027');

-- ===== K253502 AL KRAFLI Fatima Zahrae
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'fatimazahraealkrafali@gmail.com', NULL, 'Fatima Zahrae AL KRAFLI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'fatimazahraealkrafali@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'fatimazahraealkrafali@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'AL KRAFLI', 'Fatima Zahrae', 'الكرافلي', 'فاطمة الزهراء', 'F', '2005-07-03', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB262298', NULL, 'P143106964', NULL, NULL, NULL, NULL, 'fatimazahraealkrafali@gmail.com', '0752129566', '0752129566', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:42', '2026-10-15 17:16:42', '2026-10-15 16:16:43', '2026-10-15 17:16:43', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:42', '2026-10-15 16:16:42', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253502 (reprise).', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253502', 'MME', 'AL KRAFLI', 'Fatima Zahrae', 'الكرافلي', 'فاطمة الزهراء', 'F', '2005-07-03', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB262298', NULL, 'P143106964', NULL, NULL, NULL, 'fatimazahraealkrafali@gmail.com', '0752129566', '0', @u, '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253502', '2026-10-15 17:16:42', '2026-10-15 17:16:42');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253502', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253502', '2025-09-03', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');

-- ===== K253503 EL OUADRANI Mohamed Saad
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'mohamedsaadelouadrani@gmail.com', NULL, 'Mohamed Saad EL OUADRANI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'mohamedsaadelouadrani@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'mohamedsaadelouadrani@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL OUADRANI', 'Mohamed Saad', 'الودراني', 'محمد سعد', 'M', '2006-08-26', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271715', NULL, 'P143025546', NULL, NULL, NULL, NULL, 'mohamedsaadelouadrani@gmail.com', '0630738696', '0630738696', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253503 (reprise).', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253503', 'M', 'EL OUADRANI', 'Mohamed Saad', 'الودراني', 'محمد سعد', 'M', '2006-08-26', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271715', NULL, 'P143025546', NULL, NULL, NULL, 'mohamedsaadelouadrani@gmail.com', '0630738696', '0', @u, '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253503', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253503', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253503', '2025-09-11', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');

-- ===== K253505 LAZREG Omar
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'lazreg.omar111@gmail.com', NULL, 'Omar LAZREG', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'lazreg.omar111@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'lazreg.omar111@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'LAZREG', 'Omar', 'لزرق', 'عمر', 'M', '2005-03-09', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Arbaoua' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB315814', NULL, 'E120015990', NULL, NULL, NULL, NULL, 'lazreg.omar111@gmail.com', '0644768300', '064476800', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253505 (reprise).', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253505', 'M', 'LAZREG', 'Omar', 'لزرق', 'عمر', 'M', '2005-03-09', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Arbaoua' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB315814', NULL, 'E120015990', NULL, NULL, NULL, 'lazreg.omar111@gmail.com', '0644768300', '0', @u, '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253505', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253505', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253505', '2025-09-19', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');

-- ===== K253506 EL HASNAOUI Soulaimane
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'hasnaouisoulaimane58@gmail.com', NULL, 'Soulaimane EL HASNAOUI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'hasnaouisoulaimane58@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'hasnaouisoulaimane58@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL HASNAOUI', 'Soulaimane', 'الحسناوي', 'سليمان', 'M', '2007-12-22', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB275340', NULL, 'P138507098', NULL, NULL, NULL, NULL, 'hasnaouisoulaimane58@gmail.com', '0715471799', '0715471799', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253506 (reprise).', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253506', 'M', 'EL HASNAOUI', 'Soulaimane', 'الحسناوي', 'سليمان', 'M', '2007-12-22', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB275340', NULL, 'P138507098', NULL, NULL, NULL, 'hasnaouisoulaimane58@gmail.com', '0715471799', '0', @u, '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253506', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253506', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253506', '2025-09-19', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');

-- ===== K253507 EL MAKI Aziza
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'azizaelmaki058@gmail.com', NULL, 'Aziza EL MAKI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'azizaelmaki058@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'azizaelmaki058@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL MAKI', 'Aziza', 'المكي', 'عزيزة', 'F', '2004-07-24', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271961', NULL, 'P110019918', NULL, NULL, NULL, NULL, 'azizaelmaki058@gmail.com', '0707999396', '0707999396', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253507 (reprise).', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253507', 'MME', 'EL MAKI', 'Aziza', 'المكي', 'عزيزة', 'F', '2004-07-24', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271961', NULL, 'P110019918', NULL, NULL, NULL, 'azizaelmaki058@gmail.com', '0707999396', '0', @u, '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253507', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253507', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253507', '2025-09-19', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');

-- ===== K253508 BOUMHAIDI Safae
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'boumhaidisafae@gmail.com', NULL, 'Safae BOUMHAIDI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'boumhaidisafae@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'boumhaidisafae@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'BOUMHAIDI', 'Safae', 'بومهيدي', 'صفاء', 'F', '2006-05-18', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272794', NULL, 'P130097250', NULL, NULL, NULL, NULL, 'boumhaidisafae@gmail.com', '0644293445', '0644293445', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253508 (reprise).', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253508', 'MME', 'BOUMHAIDI', 'Safae', 'بومهيدي', 'صفاء', 'F', '2006-05-18', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272794', NULL, 'P130097250', NULL, NULL, NULL, 'boumhaidisafae@gmail.com', '0644293445', '0', @u, '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253508', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253508', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253508', '2025-09-22', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');

-- ===== K253509 BOUCHOUAREB Youssef
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'youssefbouchouareb8@gmail.com', NULL, 'Youssef BOUCHOUAREB', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'youssefbouchouareb8@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'youssefbouchouareb8@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'BOUCHOUAREB', 'Youssef', 'بوشوارب', 'يوسف', 'M', '2005-07-18', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB270805', NULL, 'P138088118', NULL, NULL, NULL, NULL, 'youssefbouchouareb8@gmail.com', '0700220543', '0700220543', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253509 (reprise).', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253509', 'M', 'BOUCHOUAREB', 'Youssef', 'بوشوارب', 'يوسف', 'M', '2005-07-18', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB270805', NULL, 'P138088118', NULL, NULL, NULL, 'youssefbouchouareb8@gmail.com', '0700220543', '0', @u, '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253509', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253509', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253509', '2025-09-22', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');

-- ===== K253510 MAHBOUB Muslim
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'muslimmahboub@gmail.com', NULL, 'Muslim MAHBOUB', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'muslimmahboub@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'muslimmahboub@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'MAHBOUB', 'Muslim', 'محبوب', 'مسلم', 'M', '2008-07-23', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB264614', NULL, 'P132454284', NULL, NULL, NULL, NULL, 'muslimmahboub@gmail.com', '0777546669', '0777546669', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253510 (reprise).', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253510', 'M', 'MAHBOUB', 'Muslim', 'محبوب', 'مسلم', 'M', '2008-07-23', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB264614', NULL, 'P132454284', NULL, NULL, NULL, 'muslimmahboub@gmail.com', '0777546669', '0', @u, '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253510', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253510', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253510', '2025-09-26', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:43', '2026-10-15 17:16:43');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:43', '2026-10-15 17:16:43', '1', 'Annuité 2026-2027');

-- ===== K253511 EL GORGI Mohammed
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'elgorjimohamed5@gmail.com', NULL, 'Mohammed EL GORGI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'elgorjimohamed5@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'elgorjimohamed5@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL GORGI', 'Mohammed', 'الكرجي', 'محمد', 'M', '2003-01-19', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Kenitra' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB250957', NULL, NULL, NULL, NULL, NULL, NULL, 'elgorjimohamed5@gmail.com', '0684507197', '0684507197', NULL, NULL, 'fr', NULL, NULL, NULL, NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43', '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2026-10-15 17:16:43', '2026-10-15 17:16:43');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:43', '2026-10-15 16:16:43', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253511 (reprise).', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253511', 'M', 'EL GORGI', 'Mohammed', 'الكرجي', 'محمد', 'M', '2003-01-19', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Kenitra' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB250957', NULL, NULL, NULL, NULL, NULL, 'elgorjimohamed5@gmail.com', '0684507197', '0', @u, '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', NULL, NULL, NULL, NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253511', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253511', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253511', '2025-10-14', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');

-- ===== K253512 LAHOUIDAG Yahya
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'lahwidagyahya@gmail.com', NULL, 'Yahya LAHOUIDAG', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'lahwidagyahya@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'lahwidagyahya@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'LAHOUIDAG', 'Yahya', 'لحويضك', 'يحيى', 'M', '2007-09-14', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB278019', NULL, 'P139512384', NULL, NULL, NULL, NULL, 'lahwidagyahya@gmail.com', '0625788288', '0625788288', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253512 (reprise).', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253512', 'M', 'LAHOUIDAG', 'Yahya', 'لحويضك', 'يحيى', 'M', '2007-09-14', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB278019', NULL, 'P139512384', NULL, NULL, NULL, 'lahwidagyahya@gmail.com', '0625788288', '0', @u, '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253512', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253512', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253512', '2025-09-19', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');

-- ===== K253514 EL-HARHAR Botayna
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'boutaynaelharhar05@gmail.com', NULL, 'Botayna EL-HARHAR', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'boutaynaelharhar05@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'boutaynaelharhar05@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL-HARHAR', 'Botayna', 'الهرهار', 'بثينة', 'F', '2005-02-28', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Kenitra' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB306986', NULL, 'E136070176', NULL, NULL, NULL, NULL, 'boutaynaelharhar05@gmail.com', '0632123053', '0632123053', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Techniques de gestion et comptabilité' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2022', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253514 (reprise).', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253514', 'MME', 'EL-HARHAR', 'Botayna', 'الهرهار', 'بثينة', 'F', '2005-02-28', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Kenitra' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB306986', NULL, 'E136070176', NULL, NULL, NULL, 'boutaynaelharhar05@gmail.com', '0632123053', '0', @u, '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Techniques de gestion et comptabilité' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253514', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253514', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253514', '2025-12-15', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');

-- ===== K243405 LAKRAA Achraf
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'achraflkraa05@gmail.com', NULL, 'Achraf LAKRAA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'achraflkraa05@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'achraflkraa05@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'LAKRAA', 'Achraf', 'لقرع', 'أشرف', 'M', '2005-11-11', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB269091', NULL, 'P137414722', NULL, NULL, NULL, NULL, 'achraflkraa05@gmail.com', '0696207536', '0696207536', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K243405 (reprise).', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K243405', 'M', 'LAKRAA', 'Achraf', 'لقرع', 'أشرف', 'M', '2005-11-11', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB269091', NULL, 'P137414722', NULL, NULL, NULL, 'achraflkraa05@gmail.com', '0696207536', '0', @u, '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '243405', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K243405', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K243405', '2025-09-14', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');

-- ===== K253401 K'HILA Hajar
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'khilahajar4@gmail.com', NULL, 'Hajar K\'HILA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'khilahajar4@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'khilahajar4@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'K\'HILA', 'Hajar', 'كحيلة', 'هاجر', 'F', '2006-07-21', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB324935', NULL, 'E145080762', NULL, NULL, NULL, NULL, 'khilahajar4@gmail.com', '0721147882', '0721147882', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253401 (reprise).', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253401', 'MME', 'K\'HILA', 'Hajar', 'كحيلة', 'هاجر', 'F', '2006-07-21', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB324935', NULL, 'E145080762', NULL, NULL, NULL, 'khilahajar4@gmail.com', '0721147882', '0', @u, '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253401', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253401', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253401', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');

-- ===== K253402 TALAMBOUTI Nour-El Houda
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'nourelhoudatalambouti@gmail.com', NULL, 'Nour-El Houda TALAMBOUTI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'nourelhoudatalambouti@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'nourelhoudatalambouti@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'TALAMBOUTI', 'Nour-El Houda', 'الطلمبوطي', 'نور الهدى', 'F', '2005-12-16', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Guercif‎' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB260919', NULL, 'F134045457', NULL, NULL, NULL, NULL, 'nourelhoudatalambouti@gmail.com', '0771948415', '0771948415', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2023', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253402 (reprise).', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253402', 'MME', 'TALAMBOUTI', 'Nour-El Houda', 'الطلمبوطي', 'نور الهدى', 'F', '2005-12-16', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Guercif‎' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB260919', NULL, 'F134045457', NULL, NULL, NULL, 'nourelhoudatalambouti@gmail.com', '0771948415', '0', @u, '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253402', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253402', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253402', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');

-- ===== K253403 CHAHBI Amal
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'chahbiamal72@gmail.com', NULL, 'Amal CHAHBI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'chahbiamal72@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'chahbiamal72@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'CHAHBI', 'Amal', 'الشهبي', 'أمل', 'F', '2007-01-10', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB323946', NULL, 'E147071014', NULL, NULL, NULL, NULL, 'chahbiamal72@gmail.com', '0619538352', '0619538352', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253403 (reprise).', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253403', 'MME', 'CHAHBI', 'Amal', 'الشهبي', 'أمل', 'F', '2007-01-10', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB323946', NULL, 'E147071014', NULL, NULL, NULL, 'chahbiamal72@gmail.com', '0619538352', '0', @u, '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253403', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253403', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253403', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');

-- ===== K253404 BOURKILA Mohamed Amine
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'bourkilaamine531@gmail.com', NULL, 'Mohamed Amine BOURKILA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'bourkilaamine531@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'bourkilaamine531@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'BOURKILA', 'Mohamed Amine', 'بوركيلة', 'محمد أمين', 'M', '2006-10-29', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB268894', NULL, 'P134532029', NULL, NULL, NULL, NULL, 'bourkilaamine531@gmail.com', '0716398203', '0716398203', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253404 (reprise).', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253404', 'M', 'BOURKILA', 'Mohamed Amine', 'بوركيلة', 'محمد أمين', 'M', '2006-10-29', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB268894', NULL, 'P134532029', NULL, NULL, NULL, 'bourkilaamine531@gmail.com', '0716398203', '0', @u, '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253404', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253404', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253404', '2025-09-19', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:44', '2026-10-15 17:16:44', '1', 'Annuité 2026-2027');

-- ===== K253405 HLALI Oualid
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'walidhilali1111@gmail.com', NULL, 'Oualid HLALI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'walidhilali1111@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'walidhilali1111@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'HLALI', 'Oualid', 'الهلالي', 'وليد', 'M', '2006-01-11', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB261858', NULL, 'P138499268', NULL, NULL, NULL, NULL, 'walidhilali1111@gmail.com', '0724180434', '0724180434', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:44', '2026-10-15 17:16:44', '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:44', '2026-10-15 17:16:44');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:44', '2026-10-15 16:16:44', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253405 (reprise).', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253405', 'M', 'HLALI', 'Oualid', 'الهلالي', 'وليد', 'M', '2006-01-11', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB261858', NULL, 'P138499268', NULL, NULL, NULL, 'walidhilali1111@gmail.com', '0724180434', '0', @u, '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253405', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253405', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253405', '2025-09-19', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');

-- ===== K253406 GRAIDA Marouane
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'marwanfre154@gmail.com', NULL, 'Marouane GRAIDA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'marwanfre154@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'marwanfre154@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'GRAIDA', 'Marouane', 'اكريدة', 'مروان', 'M', '2006-05-05', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB278267', NULL, 'P135523894', NULL, NULL, NULL, NULL, 'marwanfre154@gmail.com', '0713958495', '0713958495', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253406 (reprise).', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253406', 'M', 'GRAIDA', 'Marouane', 'اكريدة', 'مروان', 'M', '2006-05-05', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB278267', NULL, 'P135523894', NULL, NULL, NULL, 'marwanfre154@gmail.com', '0713958495', '0', @u, '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253406', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253406', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253406', '2025-09-19', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');

-- ===== K253407 EL ALOUI Ihab
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'ihabelalaoui005@gmail.com', NULL, 'Ihab EL ALOUI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'ihabelalaoui005@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'ihabelalaoui005@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL ALOUI', 'Ihab', 'العلوي', 'إيهاب', 'M', '2006-03-29', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271842', NULL, 'P131103228', NULL, NULL, NULL, NULL, 'ihabelalaoui005@gmail.com', '0693065819', '0693065819', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253407 (reprise).', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253407', 'M', 'EL ALOUI', 'Ihab', 'العلوي', 'إيهاب', 'M', '2006-03-29', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271842', NULL, 'P131103228', NULL, NULL, NULL, 'ihabelalaoui005@gmail.com', '0693065819', '0', @u, '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253407', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253407', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253407', '2025-09-29', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');

-- ===== K253408 SEDRAOUI Ismail
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'ismailsedraoui346@gmail.com', NULL, 'Ismail SEDRAOUI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'ismailsedraoui346@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'ismailsedraoui346@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'SEDRAOUI', 'Ismail', 'السدراوي', 'إسماعيل', 'M', '2007-01-03', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272983', NULL, 'P132322814', NULL, NULL, NULL, NULL, 'ismailsedraoui346@gmail.com', '0631855582', '0631855582', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253408 (reprise).', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253408', 'M', 'SEDRAOUI', 'Ismail', 'السدراوي', 'إسماعيل', 'M', '2007-01-03', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272983', NULL, 'P132322814', NULL, NULL, NULL, 'ismailsedraoui346@gmail.com', '0631855582', '0', @u, '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253408', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253408', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253408', '2025-09-29', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');

-- ===== K253409 EL AHMAR Ahmed
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'ahmedkser37@gmail.com', NULL, 'Ahmed EL AHMAR', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'ahmedkser37@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'ahmedkser37@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL AHMAR', 'Ahmed', 'الأحمر', 'أحمد', 'M', '2002-11-24', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB257232', NULL, 'P140031472', NULL, NULL, NULL, NULL, 'ahmedkser37@gmail.com', '0777032351', '0777032351', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253409 (reprise).', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253409', 'M', 'EL AHMAR', 'Ahmed', 'الأحمر', 'أحمد', 'M', '2002-11-24', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Larache' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB257232', NULL, 'P140031472', NULL, NULL, NULL, 'ahmedkser37@gmail.com', '0777032351', '0', @u, '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253409', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253409', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253409', '2025-10-09', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');

-- ===== K253410 SHOULI Adnane
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'shouliadnane@gmail.com', NULL, 'Adnane SHOULI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'shouliadnane@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'shouliadnane@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'SHOULI', 'Adnane', 'الصولي', 'عدنان', 'M', '2007-09-01', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB278709', NULL, 'P138519840', NULL, NULL, NULL, NULL, 'shouliadnane@gmail.com', '0631988832', '0631988832', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:04', '2026-10-15 17:44:04', '2026-10-15 16:44:04');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253410 (reprise).', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253410', 'M', 'SHOULI', 'Adnane', 'الصولي', 'عدنان', 'M', '2007-09-01', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB278709', NULL, 'P138519840', NULL, NULL, NULL, 'shouliadnane@gmail.com', '0631988832', '0', @u, '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-SRI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253410', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253410', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253410', '2025-11-29', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-SRI-25' AND c.classe_abbr = 'TS-SRI-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe A' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');

-- ===== K253801 EL KHADI Fatima
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'fatimaelkhadi20@gmail.con', NULL, 'Fatima EL KHADI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'fatimaelkhadi20@gmail.con');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'fatimaelkhadi20@gmail.con');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL KHADI', 'Fatima', 'الخادي', 'فاطمة', 'F', '2003-05-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB227524', NULL, 'P100034786', NULL, NULL, NULL, NULL, 'fatimaelkhadi20@gmail.con', '0706778304', '0706778304', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Lettres' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2022', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253801 (reprise).', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253801', 'MME', 'EL KHADI', 'Fatima', 'الخادي', 'فاطمة', 'F', '2003-05-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB227524', NULL, 'P100034786', NULL, NULL, NULL, 'fatimaelkhadi20@gmail.con', '0706778304', '0', @u, '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Lettres' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253801', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253801', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253801', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:45', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:45', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:45', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:45', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:45', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:45', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:45', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:45', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:45', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');

-- ===== K253802 HAMMOU HLIMA Fatima
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'fatimahamouhlima@gmail,com', NULL, 'Fatima HAMMOU HLIMA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'fatimahamouhlima@gmail,com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'fatimahamouhlima@gmail,com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'HAMMOU HLIMA', 'Fatima', 'حمو', 'فاطمة', 'F', '2004-08-09', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB261646', NULL, 'P132043255', NULL, NULL, NULL, NULL, 'fatimahamouhlima@gmail,com', '0706705688', '0706705688', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Lettres' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', '2026-10-15 16:16:46', '2026-10-15 17:16:46', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2022', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253802 (reprise).', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253802', 'MME', 'HAMMOU HLIMA', 'Fatima', 'حمو', 'فاطمة', 'F', '2004-08-09', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB261646', NULL, 'P132043255', NULL, NULL, NULL, 'fatimahamouhlima@gmail,com', '0706705688', '0', @u, '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Lettres' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253802', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253802', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253802', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:45', '2026-10-15 17:16:45');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:45', '2026-10-15 16:16:45', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:45', '2026-10-15 17:16:45', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:45', '2026-10-15 17:16:45', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');

-- ===== K253803 ESSARHANI Salma
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'essarhanisalma503@gmail.com', NULL, 'Salma ESSARHANI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'essarhanisalma503@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'essarhanisalma503@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'ESSARHANI', 'Salma', 'السرحاني', 'سلمى', 'F', '2007-11-29', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB275291', NULL, 'P138407043', NULL, NULL, NULL, NULL, 'essarhanisalma503@gmail.com', '0710755316', '0710755316', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253803 (reprise).', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253803', 'MME', 'ESSARHANI', 'Salma', 'السرحاني', 'سلمى', 'F', '2007-11-29', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB275291', NULL, 'P138407043', NULL, NULL, NULL, 'essarhanisalma503@gmail.com', '0710755316', '0', @u, '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253803', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253803', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253803', '2025-09-09', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');

-- ===== K253804 EL HIRECH Amal
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'elhirechamal196@gmail.com', NULL, 'Amal EL HIRECH', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'elhirechamal196@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'elhirechamal196@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL HIRECH', 'Amal', 'الحيرش', 'أمل', 'F', '2006-01-19', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB259824', NULL, 'P133528272', NULL, NULL, NULL, NULL, 'elhirechamal196@gmail.com', '0707409826', '0707409826', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253804 (reprise).', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253804', 'MME', 'EL HIRECH', 'Amal', 'الحيرش', 'أمل', 'F', '2006-01-19', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB259824', NULL, 'P133528272', NULL, NULL, NULL, 'elhirechamal196@gmail.com', '0707409826', '0', @u, '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253804', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253804', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253804', '2025-09-10', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');

-- ===== K253805 EL BOUHSSINI Yahia
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'yahia.el21@gmail.com', NULL, 'Yahia EL BOUHSSINI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'yahia.el21@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'yahia.el21@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL BOUHSSINI', 'Yahia', 'البوحسيني', 'يحيى', 'M', '1998-12-21', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB231360', NULL, 'P146104922', NULL, NULL, NULL, NULL, 'yahia.el21@gmail.com', '0633455893', '0633455893', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2018', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2018', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253805 (reprise).', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253805', 'M', 'EL BOUHSSINI', 'Yahia', 'البوحسيني', 'يحيى', 'M', '1998-12-21', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB231360', NULL, 'P146104922', NULL, NULL, NULL, 'yahia.el21@gmail.com', '0633455893', '0', @u, '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2018', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253805', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253805', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253805', '2025-09-10', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');

-- ===== K253806 EL MAAKOUL Youssef
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'youssefelmaakoul02@gmail.com', NULL, 'Youssef EL MAAKOUL', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'youssefelmaakoul02@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'youssefelmaakoul02@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL MAAKOUL', 'Youssef', 'المعقول', 'يوسف', 'M', '2002-11-30', (SELECT vil_id FROM n_villes WHERE vil_nom = 'SIDI BERNOUSSI' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'BB213905', NULL, 'R131347989', NULL, NULL, NULL, NULL, 'youssefelmaakoul02@gmail.com', '0661647691', '0777245146', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2020', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2020', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253806 (reprise).', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253806', 'M', 'EL MAAKOUL', 'Youssef', 'المعقول', 'يوسف', 'M', '2002-11-30', (SELECT vil_id FROM n_villes WHERE vil_nom = 'SIDI BERNOUSSI' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'BB213905', NULL, 'R131347989', NULL, NULL, NULL, 'youssefelmaakoul02@gmail.com', '0661647691', '0', @u, '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2020', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253806', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253806', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253806', '2025-09-12', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');

-- ===== K253807 ELKHATIB Wissal
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'wissalelkhatibee@gmail.com', NULL, 'Wissal ELKHATIB', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'wissalelkhatibee@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'wissalelkhatibee@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'ELKHATIB', 'Wissal', 'الخطيب', 'وصال', 'F', '2002-12-29', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB267750', NULL, 'P131537517', NULL, NULL, NULL, NULL, 'wissalelkhatibee@gmail.com', '0687726822', '0687726823', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2023', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253807 (reprise).', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253807', 'MME', 'ELKHATIB', 'Wissal', 'الخطيب', 'وصال', 'F', '2002-12-29', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB267750', NULL, 'P131537517', NULL, NULL, NULL, 'wissalelkhatibee@gmail.com', '0687726822', '0', @u, '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253807', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253807', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253807', '2025-09-12', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');

-- ===== K253808 GRIBA Maryame
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'maryamgriba480@gmail.com', NULL, 'Maryame GRIBA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'maryamgriba480@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'maryamgriba480@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'GRIBA', 'Maryame', 'اكريبة', 'مريم', 'F', '2008-03-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB276006', NULL, 'P147021195', NULL, NULL, NULL, NULL, 'maryamgriba480@gmail.com', '060046871', '060046872', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253808 (reprise).', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253808', 'MME', 'GRIBA', 'Maryame', 'اكريبة', 'مريم', 'F', '2008-03-04', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB276006', NULL, 'P147021195', NULL, NULL, NULL, 'maryamgriba480@gmail.com', '060046871', '0', @u, '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253808', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253808', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253808', '2025-09-18', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:46', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:46', '2026-10-15 17:16:46', '1', 'Annuité 2026-2027');

-- ===== K253809 CHEILA Kaoutar
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'cheilakaoutar@gmail.com', NULL, 'Kaoutar CHEILA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'cheilakaoutar@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'cheilakaoutar@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'CHEILA', 'Kaoutar', 'شعيلة', 'كوثر', 'F', '2005-02-08', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB267681', NULL, 'P110041940', NULL, NULL, NULL, NULL, 'cheilakaoutar@gmail.com', '0655014936', '0655014936', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:46', '2026-10-15 17:16:46', '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2023', '2026-10-15 17:16:46', '2026-10-15 17:16:46');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:46', '2026-10-15 16:16:46', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253809 (reprise).', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253809', 'MME', 'CHEILA', 'Kaoutar', 'شعيلة', 'كوثر', 'F', '2005-02-08', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB267681', NULL, 'P110041940', NULL, NULL, NULL, 'cheilakaoutar@gmail.com', '0655014936', '0', @u, '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253809', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253809', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253809', '2025-09-19', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');

-- ===== K253810 ZARROUG Hanane
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'hananezarroug2050@gmail.com', NULL, 'Hanane ZARROUG', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'hananezarroug2050@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'hananezarroug2050@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'ZARROUG', 'Hanane', 'زروق', 'حنان', 'F', '1998-02-28', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Kenitra' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB217852', NULL, 'P133511160', NULL, NULL, NULL, NULL, 'hananezarroug2050@gmail.com', '0632717302', '0632717302', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253810 (reprise).', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253810', 'MME', 'ZARROUG', 'Hanane', 'زروق', 'حنان', 'F', '1998-02-28', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Kenitra' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB217852', NULL, 'P133511160', NULL, NULL, NULL, 'hananezarroug2050@gmail.com', '0632717302', '0', @u, '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253810', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253810', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253810', '2025-09-20', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');

-- ===== K253811 ELBOUHALI Ranya
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'elbouhlirania@gmail.com', NULL, 'Ranya ELBOUHALI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'elbouhlirania@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'elbouhlirania@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'ELBOUHALI', 'Ranya', 'البوهالي', 'رانية', 'F', '2007-07-09', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB274045', NULL, 'P140022946', NULL, NULL, NULL, NULL, 'elbouhlirania@gmail.com', '0780580011', '0780580011', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2022', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253811 (reprise).', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253811', 'MME', 'ELBOUHALI', 'Ranya', 'البوهالي', 'رانية', 'F', '2007-07-09', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB274045', NULL, 'P140022946', NULL, NULL, NULL, 'elbouhlirania@gmail.com', '0780580011', '0', @u, '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253811', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253811', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253811', '2025-09-23', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');

-- ===== K253813 BENCHEKH Salma
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'benchiekhsalma90@gmail.com', NULL, 'Salma BENCHEKH', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'benchiekhsalma90@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'benchiekhsalma90@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'BENCHEKH', 'Salma', 'بنشيخ', 'سلمى', 'F', '2003-08-25', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB262135', NULL, 'P130534137', NULL, NULL, NULL, NULL, 'benchiekhsalma90@gmail.com', '0776762520', '0776762520', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2020', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2020', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253813 (reprise).', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253813', 'MME', 'BENCHEKH', 'Salma', 'بنشيخ', 'سلمى', 'F', '2003-08-25', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB262135', NULL, 'P130534137', NULL, NULL, NULL, 'benchiekhsalma90@gmail.com', '0776762520', '0', @u, '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2020', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253813', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253813', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253813', '2025-09-30', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');

-- ===== K253814 EN-NESRAOUI Iman
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'ennsraouiimane@gmail.com', NULL, 'Iman EN-NESRAOUI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'ennsraouiimane@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'ennsraouiimane@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EN-NESRAOUI', 'Iman', 'النسراوي', 'إيمان', 'F', '1992-02-14', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Arbaoua' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB176410', NULL, 'Z203900156', NULL, NULL, NULL, NULL, 'ennsraouiimane@gmail.com', '0696829240', '0696829240', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253814 (reprise).', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253814', 'MME', 'EN-NESRAOUI', 'Iman', 'النسراوي', 'إيمان', 'F', '1992-02-14', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Arbaoua' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'GB176410', NULL, 'Z203900156', NULL, NULL, NULL, 'ennsraouiimane@gmail.com', '0696829240', '0', @u, '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253814', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253814', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253814', '2025-10-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');

-- ===== K253815 BELARBI Taha
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'tahabelarbi90@gmail.com', NULL, 'Taha BELARBI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'tahabelarbi90@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'tahabelarbi90@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'BELARBI', 'Taha', 'بلعربي', 'طه', 'M', '2006-02-14', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB247235', NULL, 'P140054615', NULL, NULL, NULL, NULL, 'tahabelarbi90@gmail.com', '0774466178', '0774466179', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253815 (reprise).', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253815', 'M', 'BELARBI', 'Taha', 'بلعربي', 'طه', 'M', '2006-02-14', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB247235', NULL, 'P140054615', NULL, NULL, NULL, 'tahabelarbi90@gmail.com', '0774466178', '0', @u, '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253815', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253815', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253815', '2025-10-06', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:47', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:47', '2026-10-15 17:16:47', '1', 'Annuité 2026-2027');

-- ===== K253816 ROUIFI Marouane
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'marouane.rouifi15@gmail.com', NULL, 'Marouane ROUIFI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'marouane.rouifi15@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'marouane.rouifi15@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'ROUIFI', 'Marouane', 'الرويفي', 'مروان', 'M', '2006-04-15', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB266791', NULL, ' P139371036', NULL, NULL, NULL, NULL, 'marouane.rouifi15@gmail.com', '0623054776', '0623054776', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 17:16:47', '2026-10-15 16:16:48', '2026-10-15 17:16:48', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253816 (reprise).', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253816', 'M', 'ROUIFI', 'Marouane', 'الرويفي', 'مروان', 'M', '2006-04-15', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB266791', NULL, ' P139371036', NULL, NULL, NULL, 'marouane.rouifi15@gmail.com', '0623054776', '0', @u, '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253816', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253816', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253816', '2025-10-09', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:47', '2026-10-15 17:16:47');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:47', '2026-10-15 16:16:47', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');

-- ===== K253817 SELLOUTI Arwa
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'arwasellouti1@gmail,com', NULL, 'Arwa SELLOUTI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'arwasellouti1@gmail,com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'arwasellouti1@gmail,com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'SELLOUTI', 'Arwa', 'السلوتي', 'أروى', 'F', '2005-12-15', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB263953', NULL, 'P132525725', NULL, NULL, NULL, NULL, 'arwasellouti1@gmail,com', '0605964386', '0605964386', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253817 (reprise).', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253817', 'MME', 'SELLOUTI', 'Arwa', 'السلوتي', 'أروى', 'F', '2005-12-15', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB263953', NULL, 'P132525725', NULL, NULL, NULL, 'arwasellouti1@gmail,com', '0605964386', '0', @u, '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253817', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253817', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253817', '2025-10-13', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');

-- ===== K253818 ZEROUKI Fatima zouhra
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'fatimazouhrazerouki@gmail.com', NULL, 'Fatima zouhra ZEROUKI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'fatimazouhrazerouki@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'fatimazouhrazerouki@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'ZEROUKI', 'Fatima zouhra', 'الزروقي', 'فاطمة الزهراء', 'M', '2007-08-05', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB276828', NULL, 'P133295563', NULL, NULL, NULL, NULL, 'fatimazouhrazerouki@gmail.com', '0629111353', '0629111353', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253818 (reprise).', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253818', 'M', 'ZEROUKI', 'Fatima zouhra', 'الزروقي', 'فاطمة الزهراء', 'M', '2007-08-05', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB276828', NULL, 'P133295563', NULL, NULL, NULL, 'fatimazouhrazerouki@gmail.com', '0629111353', '0', @u, '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253818', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253818', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253818', '2025-10-20', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');

-- ===== K253819 EL KERZAZI Mounir
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'mounirkarzazi70@gmail.com', NULL, 'Mounir EL KERZAZI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'mounirkarzazi70@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'mounirkarzazi70@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL KERZAZI', 'Mounir', 'الكرزازي', 'منير', 'M', '2006-08-20', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB256528', NULL, 'P133525734', NULL, NULL, NULL, NULL, 'mounirkarzazi70@gmail.com', '0644491219', '0644491219', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253819 (reprise).', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253819', 'M', 'EL KERZAZI', 'Mounir', 'الكرزازي', 'منير', 'M', '2006-08-20', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB256528', NULL, 'P133525734', NULL, NULL, NULL, 'mounirkarzazi70@gmail.com', '0644491219', '0', @u, '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), NULL, NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253819', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253819', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253819', '2025-10-23', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');

-- ===== K253820 BOUSSAHMA Younes
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'boussahma01@gmail.com', NULL, 'Younes BOUSSAHMA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'boussahma01@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'boussahma01@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'BOUSSAHMA', 'Younes', 'بوسحمة', 'يونس', 'M', '1993-08-09', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB179557', NULL, '10710226', NULL, NULL, NULL, NULL, 'boussahma01@gmail.com', '0630100340', '0630100340', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253820 (reprise).', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253820', 'M', 'BOUSSAHMA', 'Younes', 'بوسحمة', 'يونس', 'M', '1993-08-09', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB179557', NULL, '10710226', NULL, NULL, NULL, 'boussahma01@gmail.com', '0630100340', '0', @u, '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253820', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253820', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253820', '2025-11-13', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');

-- ===== K253821 KABHA Khadija
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'kabhakhadija@gmail.com', NULL, 'Khadija KABHA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'kabhakhadija@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'kabhakhadija@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'KABHA', 'Khadija', 'كبحة', 'خديجة', 'M', '2006-06-02', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272716', NULL, 'P131039372', NULL, NULL, NULL, NULL, 'kabhakhadija@gmail.com', '0680838136', '0680838136', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253821 (reprise).', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253821', 'M', 'KABHA', 'Khadija', 'كبحة', 'خديجة', 'M', '2006-06-02', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB272716', NULL, 'P131039372', NULL, NULL, NULL, 'kabhakhadija@gmail.com', '0680838136', '0', @u, '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253821', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253821', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253821', '2025-11-28', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');

-- ===== K253823 BOUMADIAN Rania
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'ip6943890@gmail,com', NULL, 'Rania BOUMADIAN', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'ip6943890@gmail,com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'ip6943890@gmail,com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'BOUMADIAN', 'Rania', 'بومدين', 'رانية', 'M', '2006-05-08', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LA207696', NULL, 'P137288349', NULL, NULL, NULL, NULL, 'ip6943890@gmail,com', '0690763566', '0690763566', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', '2026-10-15 16:16:49', '2026-10-15 17:16:49', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253823 (reprise).', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253823', 'M', 'BOUMADIAN', 'Rania', 'بومدين', 'رانية', 'M', '2006-05-08', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LA207696', NULL, 'P137288349', NULL, NULL, NULL, 'ip6943890@gmail,com', '0690763566', '0', @u, '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253823', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253823', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253823', '2025-12-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:48', '2026-10-15 17:16:48');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:48', '2026-10-15 16:16:48', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 17:16:48', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 17:16:48', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:48', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:48', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');

-- ===== K253824 TAOUSSI Zakaria
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'zakariataoussi40@gmail.com', NULL, 'Zakaria TAOUSSI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'zakariataoussi40@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'zakariataoussi40@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'TAOUSSI', 'Zakaria', 'الطاوسي', 'زكرياء', 'M', '2005-06-23', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB243958', NULL, 'P143181038', NULL, NULL, NULL, NULL, 'zakariataoussi40@gmail.com', '0675660864', '0675660864', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2022', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253824 (reprise).', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253824', 'M', 'TAOUSSI', 'Zakaria', 'الطاوسي', 'زكرياء', 'M', '2005-06-23', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB243958', NULL, 'P143181038', NULL, NULL, NULL, 'zakariataoussi40@gmail.com', '0675660864', '0', @u, '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2022', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253824', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253824', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253824', '2025-12-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');

-- ===== K253825 TAOUSSI Amine
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'taoussiamin8@gmail.com', NULL, 'Amine TAOUSSI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'taoussiamin8@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'taoussiamin8@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/25');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'TAOUSSI', 'Amine', 'الطاوسي', 'أمين', 'M', '2004-04-30', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB244181', NULL, 'P147181039', NULL, NULL, NULL, NULL, 'taoussiamin8@gmail.com', '0675175670', '0675175670', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253825 (reprise).', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253825', 'M', 'TAOUSSI', 'Amine', 'الطاوسي', 'أمين', 'M', '2004-04-30', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB244181', NULL, 'P147181039', NULL, NULL, NULL, 'taoussiamin8@gmail.com', '0675175670', '0', @u, '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/25'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-GE-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253825', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2025-2026' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253825', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'validee' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253825', '2025-12-17', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-GE-25' AND c.classe_abbr = 'TS-GE-2A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');

-- ===== K253301 EL MAJDOUB Ayoub
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'ayoub.elmajdoub1999@gmail.com', NULL, 'Ayoub EL MAJDOUB', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'ayoub.elmajdoub1999@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'ayoub.elmajdoub1999@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL MAJDOUB', 'Ayoub', 'المجذوب', 'أيوب', 'M', '1999-12-16', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB229190', NULL, 'A214154910', NULL, NULL, NULL, NULL, 'ayoub.elmajdoub1999@gmail.com', '0654769498', '0654769498', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253301 (reprise).', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253301', 'M', 'EL MAJDOUB', 'Ayoub', 'المجذوب', 'أيوب', 'M', '1999-12-16', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB229190', NULL, 'A214154910', NULL, NULL, NULL, 'ayoub.elmajdoub1999@gmail.com', '0654769498', '0', @u, '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253301', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253301', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');

-- ===== K253302 HADRACHI Imane
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'hadrachiimane@gmail.ma', NULL, 'Imane HADRACHI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'hadrachiimane@gmail.ma');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'hadrachiimane@gmail.ma');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'HADRACHI', 'Imane', 'حضراشي', 'إيمان', 'F', '2006-11-06', (SELECT vil_id FROM n_villes WHERE vil_nom = 'RABAT' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB270314', NULL, 'P134103595', NULL, NULL, NULL, NULL, 'hadrachiimane@gmail.ma', '0615953337', '0776015928', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2023', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253302 (reprise).', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253302', 'MME', 'HADRACHI', 'Imane', 'حضراشي', 'إيمان', 'F', '2006-11-06', (SELECT vil_id FROM n_villes WHERE vil_nom = 'RABAT' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB270314', NULL, 'P134103595', NULL, NULL, NULL, 'hadrachiimane@gmail.ma', '0615953337', '0', @u, '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-09-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2023', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253302', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253302', '2025-09-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');

-- ===== K253303 SAMRI Imane
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'samri.imane02@gmail.com', NULL, 'Imane SAMRI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'samri.imane02@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'samri.imane02@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'SAMRI', 'Imane', 'السمري', 'إيمان', 'F', '2005-06-10', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB258033', NULL, 'P120089621', NULL, NULL, NULL, NULL, 'samri.imane02@gmail.com', '0703276887', NULL, NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253303 (reprise).', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253303', 'MME', 'SAMRI', 'Imane', 'السمري', 'إيمان', 'F', '2005-06-10', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB258033', NULL, 'P120089621', NULL, NULL, NULL, 'samri.imane02@gmail.com', '0703276887', '0', @u, '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-09-09', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253303', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253303', '2025-09-09', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');

-- ===== K253304 LANJRI Adnan
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'lanjriadnan9@gmail.com', NULL, 'Adnan LANJRI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'lanjriadnan9@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'lanjriadnan9@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'LANJRI', 'Adnan', 'لنجري', 'عدنان', 'M', '2006-11-07', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB267957', NULL, 'P135103230', NULL, NULL, NULL, NULL, 'lanjriadnan9@gmail.com', '605907408', '605907408', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253304 (reprise).', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253304', 'M', 'LANJRI', 'Adnan', 'لنجري', 'عدنان', 'M', '2006-11-07', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB267957', NULL, 'P135103230', NULL, NULL, NULL, 'lanjriadnan9@gmail.com', '605907408', '0', @u, '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-09-10', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253304', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253304', '2025-09-10', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:49', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:49', '2026-10-15 17:16:49', '1', 'Annuité 2026-2027');

-- ===== K253305 BENKHADIJA Salmane
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'salmanbenkhadija@gmail.com', NULL, 'Salmane BENKHADIJA', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'salmanbenkhadija@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'salmanbenkhadija@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'BENKHADIJA', 'Salmane', 'بن خديجة', 'سلمان', 'M', '2006-12-20', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB264298', NULL, 'P142007595', NULL, NULL, NULL, NULL, 'salmanbenkhadija@gmail.com', '0770169419', '0770169419', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:49', '2026-10-15 17:16:49', '2026-10-15 16:16:50', '2026-10-15 17:16:50', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:49', '2026-10-15 17:16:49');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:49', '2026-10-15 16:16:49', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253305 (reprise).', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253305', 'M', 'BENKHADIJA', 'Salmane', 'بن خديجة', 'سلمان', 'M', '2006-12-20', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB264298', NULL, 'P142007595', NULL, NULL, NULL, 'salmanbenkhadija@gmail.com', '0770169419', '0', @u, '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-09-22', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253305', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253305', '2025-09-22', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');

-- ===== K253306 AARIF Fedraouss
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'aarifferdaous@gmail.com', NULL, 'Fedraouss AARIF', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'aarifferdaous@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'aarifferdaous@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'AARIF', 'Fedraouss', 'عارف', 'فردوس', 'F', '2004-06-29', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB247875', NULL, 'P144063567', NULL, NULL, NULL, NULL, 'aarifferdaous@gmail.com', '0674479493', '0674479493', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2018', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2018', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253306 (reprise).', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253306', 'MME', 'AARIF', 'Fedraouss', 'عارف', 'فردوس', 'F', '2004-06-29', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB247875', NULL, 'P144063567', NULL, NULL, NULL, 'aarifferdaous@gmail.com', '0674479493', '0', @u, '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-10-02', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2018', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253306', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253306', '2025-10-02', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');

-- ===== K253307 RAHMOUNI Mohamed
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'cvmoha1998@gmail.com', NULL, 'Mohamed RAHMOUNI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'cvmoha1998@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'cvmoha1998@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'RAHMOUNI', 'Mohamed', 'الرحموني', 'محمد', 'M', '1998-01-01', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ouazzane' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB221804', NULL, 'P142058798', NULL, NULL, NULL, NULL, 'cvmoha1998@gmail.com', '0624486034', '0624486034', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253307 (reprise).', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253307', 'M', 'RAHMOUNI', 'Mohamed', 'الرحموني', 'محمد', 'M', '1998-01-01', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ouazzane' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB221804', NULL, 'P142058798', NULL, NULL, NULL, 'cvmoha1998@gmail.com', '0624486034', '0', @u, '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-10-03', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Science de la vie et de la terre' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253307', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253307', '2025-10-03', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');

-- ===== K253308 KANDIL Abderahmim
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'abdrrahimkandil6@gmail.com', NULL, 'Abderahmim KANDIL', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'abdrrahimkandil6@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'abdrrahimkandil6@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'KANDIL', 'Abderahmim', 'قنديل', 'عبد الرحيم', 'M', '2007-08-08', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB277688', NULL, 'P140161196', NULL, NULL, NULL, NULL, 'abdrrahimkandil6@gmail.com', '0657496975', '0657496975', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2019', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2019', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253308 (reprise).', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253308', 'M', 'KANDIL', 'Abderahmim', 'قنديل', 'عبد الرحيم', 'M', '2007-08-08', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB277688', NULL, 'P140161196', NULL, NULL, NULL, 'abdrrahimkandil6@gmail.com', '0657496975', '0', @u, '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-10-06', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2019', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253308', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253308', '2025-10-06', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');

-- ===== K253309 MOUAFIK Amal
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'amalmouafik753@gmail.com', NULL, 'Amal MOUAFIK', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'amalmouafik753@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'amalmouafik753@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'MOUAFIK', 'Amal', 'موافق', 'أمل', 'F', '2001-08-01', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB241964', NULL, 'P142114934', NULL, NULL, NULL, NULL, 'amalmouafik753@gmail.com', NULL, '0768674253', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253309 (reprise).', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253309', 'MME', 'MOUAFIK', 'Amal', 'موافق', 'أمل', 'F', '2001-08-01', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB241964', NULL, 'P142114934', NULL, NULL, NULL, 'amalmouafik753@gmail.com', NULL, '0', @u, '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-10-06', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Économique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences économiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253309', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253309', '2025-10-06', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');

-- ===== K253310 HARRAK Abdellatif
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'abdellatif12harrak@gmail.com', NULL, 'Abdellatif HARRAK', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'abdellatif12harrak@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'abdellatif12harrak@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'HARRAK', 'Abdellatif', 'حراق', 'عبد اللطيف', 'M', '2003-06-25', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB245466', NULL, 'P13390229', NULL, NULL, NULL, NULL, 'abdellatif12harrak@gmail.com', '0689763899', '0689763899', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2025', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253310 (reprise).', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253310', 'M', 'HARRAK', 'Abdellatif', 'حراق', 'عبد اللطيف', 'M', '2003-06-25', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB245466', NULL, 'P13390229', NULL, NULL, NULL, 'abdellatif12harrak@gmail.com', '0689763899', '0', @u, '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-10-07', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2025', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253310', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253310', '2025-10-07', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');

-- ===== K253312 EL ATAR Mohamed
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'mohamedatar755@gmail.com', NULL, 'Mohamed EL ATAR', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'mohamedatar755@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'mohamedatar755@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'M', 'EL ATAR', 'Mohamed', 'العطار', 'محمد', 'M', '2005-10-30', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271585', NULL, 'P138063002', NULL, NULL, NULL, NULL, 'mohamedatar755@gmail.com', '0645313848', '0645313848', NULL, NULL, 'fr', NULL, NULL, '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253312 (reprise).', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253312', 'M', 'EL ATAR', 'Mohamed', 'العطار', 'محمد', 'M', '2005-10-30', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB271585', NULL, 'P138063002', NULL, NULL, NULL, 'mohamedatar755@gmail.com', '0645313848', '0', @u, '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-10-13', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', NULL, NULL, '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253312', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253312', '2025-10-13', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:50', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:50', '2026-10-15 17:16:50', '1', 'Annuité 2026-2027');

-- ===== K253313 EL ATTAR Bochra
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'bochraelattar61@gmail.com', NULL, 'Bochra EL ATTAR', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'bochraelattar61@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'bochraelattar61@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL ATTAR', 'Bochra', 'العطار', 'بشرى', 'F', '2006-04-13', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB260380', NULL, 'P137046588', NULL, NULL, NULL, NULL, 'bochraelattar61@gmail.com', '0607335931', '0607335931', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:50', '2026-10-15 17:16:50', '2026-10-15 16:16:51', '2026-10-15 17:16:51', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:50', '2026-10-15 17:16:50');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:50', '2026-10-15 16:16:50', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253313 (reprise).', NULL, '2026-10-15 17:16:51', '2026-10-15 16:16:51', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253313', 'MME', 'EL ATTAR', 'Bochra', 'العطار', 'بشرى', 'F', '2006-04-13', NULL, (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB260380', NULL, 'P137046588', NULL, NULL, NULL, 'bochraelattar61@gmail.com', '0607335931', '0', @u, '2026-10-15 17:16:51', '2026-10-15 17:16:51');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-10-13', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253313', '2026-10-15 17:16:51', '2026-10-15 17:16:51');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253313', '2025-10-13', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:51', '2026-10-15 17:16:51');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:51', '2026-10-15 16:16:51', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:51', '2026-10-15 17:16:51', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:51', '2026-10-15 17:16:51', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:51', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:51', '2026-10-15 17:16:51', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:51', '2026-10-15 17:16:51', '1', 'Annuité 2026-2027');

-- ===== K253315 KOSSAIR Zaynab
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'qassirzainab@gmail.com', NULL, 'Zaynab KOSSAIR', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'qassirzainab@gmail.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'qassirzainab@gmail.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'KOSSAIR', 'Zaynab', 'قصير', 'زينب', 'F', '2005-10-10', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB264250', NULL, 'P120088006', NULL, NULL, NULL, NULL, 'qassirzainab@gmail.com', '0722742311', '0722742311', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:51', '2026-10-15 17:16:51', '2026-10-15 17:16:51', '2026-10-15 17:16:51', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2024', '2026-10-15 17:16:51', '2026-10-15 17:16:51');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:51', '2026-10-15 16:16:51', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253315 (reprise).', NULL, '2026-10-15 17:16:51', '2026-10-15 16:16:51', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253315', 'MME', 'KOSSAIR', 'Zaynab', 'قصير', 'زينب', 'F', '2005-10-10', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB264250', NULL, 'P120088006', NULL, NULL, NULL, 'qassirzainab@gmail.com', '0722742311', '0', @u, '2026-10-15 17:16:51', '2026-10-15 17:16:51');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-11-01', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Scientifique' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences physiques' ORDER BY sb_id LIMIT 1), '2024', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253315', '2026-10-15 17:16:51', '2026-10-15 17:16:51');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253315', '2025-11-01', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:51', '2026-10-15 17:16:51');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:51', '2026-10-15 16:16:51', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:51', '2026-10-15 17:16:51', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:51', '2026-10-15 17:16:51', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:51', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:51', '2026-10-15 17:16:51', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:51', '2026-10-15 17:16:51', '1', 'Annuité 2026-2027');

-- ===== K253316 EL FLIHI Karima
INSERT INTO n_utilisateurs (user_email, user_password, user_nom_affiche, user_est_actif, created_at) SELECT 'karimaelflihi90@icloud.com', NULL, 'Karima EL FLIHI', 1, NOW() FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM n_utilisateurs WHERE user_email = 'karimaelflihi90@icloud.com');
SET @u := (SELECT user_id FROM n_utilisateurs WHERE user_email = 'karimaelflihi90@icloud.com');
INSERT IGNORE INTO n_utilisateur_roles (ur_user_id, ur_role_id) VALUES (@u, @role_etudiant);
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('P', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'P' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
SET @pre_numero := CONCAT('P', LPAD(@seq, 5, '0'), '/26');
INSERT INTO n_preinscriptions (pre_seq, pre_numero, pre_as_id, pre_source, pre_civilite, pre_nom, pre_prenom, pre_nom_ar, pre_prenom_ar, pre_sexe, pre_date_naissance, pre_ville_naissance_id, pre_nat_id, pre_cin, pre_passeport, pre_code_massar, pre_situation_famille, pre_est_handicape, pre_est_salarie, pre_pere_affilie_cnss, pre_email, pre_tel, pre_whatsapp, pre_adresse, pre_ville_id, pre_langue, pre_type_bac_id, pre_serie_bac_id, pre_bac_annee, pre_bac_mention_id, pre_bac_etablissement, pre_bac_pays_id, pre_bac_ville_id, pre_centre_id, pre_site_id, pre_niv_id, pre_for_id, pre_classe_id, pre_mode_id, pre_garant_nom, pre_garant_tel, pre_commercial_id, pre_utilisateur_id, pre_statut_prospect_id, pre_canal_precision, pre_droit_modif, pre_cgu_version, pre_cgu_acceptees_le, pre_soumise_le, created_at, updated_at, pre_derniere_action_le, pre_tags) VALUES (@seq, @pre_numero, @a, 'A', 'MME', 'EL FLIHI', 'Karima', 'الفليحي', 'كريمة', 'F', '1997-08-12', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB221596', NULL, 'P134513905', NULL, NULL, NULL, NULL, 'karimaelflihi90@icloud.com', '0724696326', '0724696326', NULL, NULL, 'fr', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2016', NULL, NULL, NULL, NULL, @ksar, @site, (SELECT niv_id FROM n_niveaux WHERE niv_numero = '1' ORDER BY niv_id LIMIT 1), (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), NULL, NULL, NULL, @u, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), NULL, '1', NULL, NULL, '2026-10-15 17:16:51', '2026-10-15 17:16:51', '2026-10-15 17:16:51', '2026-10-15 17:16:51', NULL);
SET @pre := LAST_INSERT_ID();
INSERT INTO n_diplomes_acces (da_preins_id, da_type_diplome_id, da_specialite, da_mention_id, da_etablissement, da_type_etablissement, da_pays_id, da_ville_id, da_annee, created_at, updated_at) VALUES (@pre, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, NULL, NULL, NULL, NULL, '2016', '2026-10-15 17:16:51', '2026-10-15 17:16:51');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-PID' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'CPL-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_preinscription_criteres (pc_preins_id, pc_ca_id, pc_sc_id, pc_est_obligatoire, pc_commentaire, pc_valide_par, pc_valide_le, created_at, updated_at) VALUES (@pre, (SELECT ca_id FROM n_criteres_access WHERE ca_code = 'RDN-BAC' ORDER BY ca_id LIMIT 1), (SELECT sc_id FROM n_statuts_criteres WHERE sc_code = 'accepte' ORDER BY sc_id LIMIT 1), '1', 'Dossier repris de l’ancien système (Ksar El Kébir).', NULL, '2026-10-15 17:44:05', '2026-10-15 17:44:05', '2026-10-15 16:44:05');
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'nouveau' ORDER BY stp_id LIMIT 1), 'Préinscription enregistrée.', NULL, '2026-10-15 17:16:51', '2026-10-15 16:16:51', NULL);
INSERT INTO n_historique_statut (hs_pre_id, hs_statut_id, hs_commentaire, hs_user_id, hs_date_changement, created_at, updated_at) VALUES (@pre, (SELECT stp_id FROM n_statuts_prospect WHERE stp_code = 'inscrit' ORDER BY stp_id LIMIT 1), 'Inscription K253316 (reprise).', NULL, '2026-10-15 17:16:51', '2026-10-15 16:16:51', NULL);
INSERT INTO n_etudiants (etud_matricule, etud_civilite, etud_nom, etud_prenom, etud_nom_ar, etud_prenom_ar, etud_sexe, etud_date_naissance, etud_ville_naissance_id, etud_nat_id, etud_cin, etud_passeport, etud_code_massar, etud_carte_sejour_expiration, etud_adresse, etud_ville_id, etud_email, etud_tel, etud_est_decale, etud_user_id, created_at, updated_at) VALUES ('K253316', 'MME', 'EL FLIHI', 'Karima', 'الفليحي', 'كريمة', 'F', '1997-08-12', (SELECT vil_id FROM n_villes WHERE vil_nom = 'Ksar El Kébir' ORDER BY vil_id LIMIT 1), (SELECT nat_id FROM n_nationalites WHERE nat_nom = 'Marocaine' ORDER BY nat_id LIMIT 1), 'LB221596', NULL, 'P134513905', NULL, NULL, NULL, 'karimaelflihi90@icloud.com', '0724696326', '0', @u, '2026-10-15 17:16:51', '2026-10-15 17:16:51');
SET @etu := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('A', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'A' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_admissions (adm_seq, adm_numero, adm_date, adm_type, adm_etudiant_id, adm_preins_id, adm_as_id, adm_formation_id, adm_centre_id, adm_centre_admin_id, adm_site_id, adm_statut_id, adm_situation, adm_est_principale, adm_est_centre_paiement, adm_type_bac_id, adm_serie_bac_id, adm_bac_annee, adm_bac_mention_id, adm_bac_etablissement, adm_bac_ville_id, adm_diplome_acces_type_id, adm_diplome_acces_specialite, adm_premiere_annee_sup, adm_handicap, adm_est_resident, adm_est_fonctionnaire, adm_est_mobilite, adm_bourse_pourcentage, adm_localite_id, adm_accord_peda, adm_commentaire_peda, adm_accord_admin, adm_commentaire_admin, adm_mise_a_niveau, adm_ref_externe, created_at, updated_at) VALUES (@seq, CONCAT('A', LPAD(@seq, 5, '0'), '/26'), '2025-12-06', 'M', @etu, @pre, @a, (SELECT for_id FROM n_formations WHERE for_centre_id = @ksar AND for_abbr = 'DTS-DI-25'), @ksar, @ksar, @site, (SELECT sa_id FROM n_statuts_admissions WHERE sa_code = 'active' ORDER BY sa_id LIMIT 1), 'N', '1', '1', (SELECT tb_id FROM n_types_bac WHERE tb_nom = 'Baccalauréat Littéraire' ORDER BY tb_id LIMIT 1), (SELECT sb_id FROM n_series_bac WHERE sb_nom = 'Sciences humaines' ORDER BY sb_id LIMIT 1), '2016', NULL, NULL, NULL, (SELECT tda_id FROM n_types_diplomes_acces WHERE tda_nom = 'Baccalauréat' ORDER BY tda_id LIMIT 1), NULL, NULL, 'N', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '253316', '2026-10-15 17:16:51', '2026-10-15 17:16:51');
SET @adm := LAST_INSERT_ID();
SET @a := (SELECT as_id FROM n_annees_scolaires WHERE as_nom = '2026-2027' ORDER BY as_id LIMIT 1);
INSERT IGNORE INTO n_sequences (seq_type, seq_as_id, seq_centre_id, seq_valeur) VALUES ('I', @a, NULL, 0);
UPDATE n_sequences SET seq_valeur = LAST_INSERT_ID(seq_valeur + 1) WHERE seq_type = 'I' AND seq_as_id = @a AND seq_centre_id IS NULL;
SET @seq := LAST_INSERT_ID();
INSERT INTO n_inscriptions (ins_seq, ins_numero, ins_date, ins_adm_id, ins_etudiant_id, ins_as_id, ins_classe_id, ins_grp_id, ins_mode_id, ins_site_id, ins_statut_id, ins_abandon_declare_le, ins_note_est_affichee, created_at, updated_at) VALUES (@seq, 'K253316', '2025-12-06', @adm, @etu, @a, (SELECT c.classe_id FROM n_classes c JOIN n_formations f ON f.for_id = c.classe_formation_id WHERE f.for_centre_id = @ksar AND f.for_abbr = 'DTS-DI-25' AND c.classe_abbr = 'TS-DI-1A'), (SELECT grp_id FROM n_groupes WHERE grp_nom = 'Groupe B' ORDER BY grp_id LIMIT 1), (SELECT mode_id FROM n_modes_enseignement WHERE mode_code = 'P' ORDER BY mode_id LIMIT 1), @site, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, '1', '2026-10-15 17:16:51', '2026-10-15 17:16:51');
SET @ins := LAST_INSERT_ID();
INSERT INTO n_historique_statuts_inscription (hsi_ins_id, hsi_de_id, hsi_vers_id, hsi_motif, hsi_user_id, hsi_date, created_at, updated_at) VALUES (@ins, NULL, (SELECT si_id FROM n_statuts_inscriptions WHERE si_code = 'en_cours' ORDER BY si_id LIMIT 1), NULL, NULL, '2026-10-15 17:16:51', '2026-10-15 16:16:51', NULL);
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FI' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:51', '2026-10-15 17:16:51', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:51', '2026-10-15 17:16:51', '1', 'Annuité 2026-2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FS' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Mensualité' ORDER BY tp_id LIMIT 1), '8000.00', 'MAD', NULL, '2026-10-15 17:16:51', '2026-10-15 16:18:33', NULL, '2026-10-01', '2027-07-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '1', 'Octobre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 2 LIMIT 1), '800.00', '2026-11-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '2', 'Novembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 3 LIMIT 1), '800.00', '2026-12-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '3', 'Décembre 2026');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 4 LIMIT 1), '800.00', '2027-01-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '4', 'Janvier 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 5 LIMIT 1), '800.00', '2027-02-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '5', 'Février 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 6 LIMIT 1), '800.00', '2027-03-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '6', 'Mars 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 7 LIMIT 1), '800.00', '2027-04-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '7', 'Avril 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 8 LIMIT 1), '800.00', '2027-05-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '8', 'Mai 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 9 LIMIT 1), '800.00', '2027-06-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '9', 'Juin 2027');
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Mensualité' AND p.periode_ordre = 10 LIMIT 1), '800.00', '2027-07-05', '2026-10-15 17:16:51', '2026-10-15 16:18:32', '10', 'Juillet 2027');
INSERT INTO n_fraisconvenu (fcv_ins_id, fcv_typefrais_id, fcv_typeperiode_id, fcv_montant, fcv_devise, fcv_cree_par, created_at, updated_at, fcv_plp_id, fcv_date_debut, fcv_date_fin) VALUES (@ins, (SELECT tpf_id FROM n_types_frais WHERE tpf_code = 'FD' ORDER BY tpf_id LIMIT 1), (SELECT tp_id FROM n_types_periodes_frais WHERE tp_nom = 'Annuité' ORDER BY tp_id LIMIT 1), '800.00', 'MAD', NULL, '2026-10-15 17:16:51', '2026-10-15 17:16:51', NULL, '2026-10-01', '2026-10-01');
SET @fcv := LAST_INSERT_ID();
INSERT INTO n_periodes_convenues (pcv_fcv_id, pcv_periode_id, pcv_montant, pcv_date_echeance, created_at, updated_at, pcv_ordre, pcv_libelle) VALUES (@fcv, (SELECT p.periode_id FROM n_periodes_frais p JOIN n_types_periodes_frais t ON t.tp_id = p.periode_tp_id WHERE t.tp_nom = 'Annuité' AND p.periode_ordre = 1 LIMIT 1), '800.00', '2026-10-05', '2026-10-15 17:16:51', '2026-10-15 17:16:51', '1', 'Annuité 2026-2027');
COMMIT;

-- Vérification
SELECT a.as_nom, c.classe_abbr, COUNT(*) AS inscrits FROM n_inscriptions i JOIN n_classes c ON c.classe_id = i.ins_classe_id
JOIN n_annees_scolaires a ON a.as_id = i.ins_as_id WHERE c.classe_centre_id = @ksar GROUP BY a.as_nom, c.classe_abbr ORDER BY a.as_nom, c.classe_abbr;
