diff --git a/application/controllers/Gestion.php b/application/controllers/Gestion.php index cdb9741d..bb5e581e 100755 --- a/application/controllers/Gestion.php +++ b/application/controllers/Gestion.php @@ -2645,5 +2645,80 @@ class Gestion extends CI_Controller echo json_encode($data); } + public function validate_request_agency() { + if ($this->isLogged()) { + $id = $this->input->post('id'); + $doc_front = $this->input->post('doc_front'); + $doc_back = $this->input->post('doc_back'); + + $this->db->trans_begin(); + + $updateLocal = $this->user_model->updateRequestStatus($id, 'validated'); + log_message('info', 'Validation de la demande d\'ouverture de compte agence bancaire ID_demande ' . $id); + + if ($updateLocal) { + + $url = WALLET_SERVICE_URL . '/wallets/users/activate_user_bank_account'; + + $body = [ + 'id' => $id, + 'doc_front' => $doc_front, + 'doc_back' => $doc_back + // Vous pouvez ajouter ici l'ID de l'admin qui valide si nécessaire + // 'validated_by' => $this->session->userdata('user_id') + ]; + + $payload = json_encode($body); + + $ch = curl_init($url); + + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); + + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($payload), + 'Authorization: ' . WALLET_SERVICE_TOKEN, + 'X-localization: ' . ($this->session->userdata('site_lang') == 'french' ? 'fr' : 'en') + )); + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + // Exécution + $result = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ($result && ($httpCode >= 200 && $httpCode < 300)) { + + $this->db->trans_commit(); + + echo json_encode([ + 'success' => 'ok', + 'message' => 'Compte créé avec succès.', + 'api_response' => json_decode($result) + ]); + } else { + + $this->db->trans_rollback(); + + echo json_encode([ + 'success' => 'false', + 'message' => 'Un problème est survenu lors de l\'ouverture du compte (' . $httpCode . ')', + 'api_error' => $result + ]); + log_message('error', 'Erreur API lors de l\'ouverture du compte agence bancaire ID_demande ' . $id . ' : ' . $result); + + } + } else { + + // ECHEC LOCAL : ON ANNULE LA TRANSACTION (ROLLBACK) + $this->db->trans_rollback(); + + echo json_encode(['alert' => 'error', 'success' => 'false', 'message' => 'Erreur lors de l\'activation du compte']); + } + } + } + } diff --git a/application/language/english/message_lang.php b/application/language/english/message_lang.php index 4ce84bdd..fd6317af 100755 --- a/application/language/english/message_lang.php +++ b/application/language/english/message_lang.php @@ -1102,4 +1102,5 @@ $lang['status_rejected'] = 'Rejected'; $lang['status_validated'] = 'Validated'; $lang['subscriptions_history'] = "Subscription history"; $lang["list_of_request_opening_bank_accounts"] = "List of bank account opening requests"; +$lang["product"] = "Product"; ?> diff --git a/application/language/french/message_lang.php b/application/language/french/message_lang.php index 683058f6..644915e9 100755 --- a/application/language/french/message_lang.php +++ b/application/language/french/message_lang.php @@ -1109,5 +1109,5 @@ $lang['status_close'] = 'Fermé'; $lang['status_rejected'] = 'Rejeté'; $lang['status_validated'] = 'Validé'; $lang['subscriptions_history'] = 'Historique des souscriptions'; - +$lang["product"] = "Produit"; ?> diff --git a/application/models/User_model.php b/application/models/User_model.php index 36124216..d3017cb9 100755 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -2324,8 +2324,24 @@ class User_model extends CI_Model } function getAllRequests(){ - $result = $this->db->query("SELECT * FROM user_bank_accounts")->result(); - return $result; + $this->db->select(' + user_bank_accounts.*, + customer_account_types.name as type, + identifications.document_image_front, + identifications.document_image_back + '); + + $this->db->from('user_bank_accounts'); + + // Jointure type de compte + $this->db->join('customer_account_types', 'user_bank_accounts.customer_account_type_id = customer_account_types.id', 'left'); + + // Jointure identifications (Assurez-vous que 'id_user' est bien la clé de liaison dans user_bank_accounts) + $this->db->join('identifications', 'identifications.id_user = user_bank_accounts.id_user', 'left'); + + $this->db->order_by('user_bank_accounts.id', 'DESC'); + + return $this->db->get()->result(); } public function updateInfoAgency($id, $data) { @@ -2371,4 +2387,9 @@ class User_model extends CI_Model $query = $this->db->get(); return $query->num_rows() > 0 ? $query->result() : []; // Retourne un tableau d'objets } + + public function updateRequestStatus($id, $status) { + $this->db->where("id", $id); + return $this->db->update("user_bank_accounts", ['status' => $status, 'reason' => 'En attente d\'activation de compte']); + } } diff --git a/application/views/account_opening_agent/infos_opening_account_request.php b/application/views/account_opening_agent/infos_opening_account_request.php index 22a3ed01..02f13ecf 100755 --- a/application/views/account_opening_agent/infos_opening_account_request.php +++ b/application/views/account_opening_agent/infos_opening_account_request.php @@ -202,71 +202,12 @@ lang->line('birth_country') ?> birth_country ?> - - lang->line('birth_locality'); ?> - birth_locality ?> - - - - - - - -
-
-

lang->line('parent_informations') ?>

-
-
-
- - - - - - - - - - - - - - - - - - - - - -
lang->line('father_lastname'); ?>father_lastname; ?>
lang->line('father_firstname'); ?>father_firstname; ?>
-
-
- - - - - - - - - - - - - - - - - - - -
lang->line('mother_birth_lastname'); ?>mother_birth_lastname; ?>
lang->line('mother_firstname'); ?>mother_firstname; ?>
+
@@ -292,11 +233,7 @@ lang->line('spouse_lastname'); ?> - spouse_lastname; ?> - - - lang->line('spouse_firstname'); ?> - spouse_firstname; ?> + spouse_name; ?> diff --git a/application/views/config_wallet_ilink_hyp/customers_accounts.php b/application/views/config_wallet_ilink_hyp/customers_accounts.php index aece4736..323606fe 100755 --- a/application/views/config_wallet_ilink_hyp/customers_accounts.php +++ b/application/views/config_wallet_ilink_hyp/customers_accounts.php @@ -31,6 +31,7 @@ # lang->line('Nom'); ?> + lang->line('product'); ?> Description Parent lang->line('opening_amount'); ?> @@ -43,12 +44,13 @@ name?> + product?> description?> parent?> opening_amount) ? '' : Money::of(round($row->opening_amount, 2), $currency_code ?? 'XAF', $context)->formatTo('fr_FR')?> opening_amount_payment_period_days?> - @@ -74,6 +76,10 @@
+
+ + +
@@ -89,9 +95,12 @@
@@ -120,6 +129,10 @@
+
+ + +
@@ -285,6 +298,7 @@ $(document).on("click", ".edit-doc", function () { selectedId = $(this).data('id'); $("#update-form input[name='name']").val($(this).data('name')); + $("#update-form input[name='product']").val($(this).data('product')); $("#update-form textarea[name='description']").val($(this).data('description')); $("#update-form input[name='opening_amount']").val($(this).data('opening_amount')); $("#update-form input[name='opening_amount_payment_period_days']").val($(this).data('opening_amount_payment_period_days')); @@ -347,6 +361,7 @@ id: selectedId, network_id : networkId, name: $("input[name=name]",this).val(), + product: $("input[name=product]",this).val(), description: $("textarea[name=description]",this).val(), opening_amount: $("input[name=opening_amount]",this).val(), opening_amount_payment_period_days: $("input[name=opening_amount_payment_period_days]", this).val(), @@ -391,6 +406,7 @@ data: { network_id: networkId, name: $("input[name=name]", this).val(), + product: $("input[name=product]", this).val(), description: $("textarea[name=description]", this).val(), opening_amount: $("input[name=opening_amount]", this).val(), opening_amount_payment_period_days: $("input[name=opening_amount_payment_period_days]", this).val(), diff --git a/application/views/gestion_agency_banking.php b/application/views/gestion_agency_banking.php index a0a0328a..32f781f3 100755 --- a/application/views/gestion_agency_banking.php +++ b/application/views/gestion_agency_banking.php @@ -53,7 +53,12 @@ lang->line('account'); ?> IBAN Type - lang->line('balance'); ?> + lang->line('nationality'); ?> + lang->line('birth_date'); ?> + lang->line('birth_country'); ?> + lang->line('marital_status'); ?> + lang->line('phone_number'); ?> + lang->line('reason'); ?> lang->line('status'); ?> Actions @@ -68,8 +73,13 @@ firstname ?> account_number ?> iban ?> - account_type ?> - balance,0,',',' ') ?> + type ?> + nationality ?> + birth_date ?> + birth_country ?> + marital_status) ?> + phone_number ?> + reason ?> status, $this->lang) ?> @@ -85,22 +95,28 @@ data-lastname="lastname ?>" data-firstname="firstname ?>" data-account_number="account_number ?>" + data-customer_number="customer_number ?>" data-iban="iban ?>" - data-swift_code="swift_code ?>" + data-phone_number="phone_number ?>" data-status="status ?>" data-reason="reason ?>" data-balance="balance ?>" - data-account_type="account_type ?>" + data-type="type ?>" data-birth_date="birth_date ?>" data-birth_country="birth_country ?>" data-birth_city="birth_city ?>" data-nationality="nationality ?>" data-marital_status="marital_status ?>" data-profession="profession ?>" - data-sector_activity="sector_activity ?>" - data-tax_number="tax_number ?>" + data-identification_number="identification_number ?>" + data-niu="niu ?>" + data-spouse_name="spouse_name ?>" + data-employer_city="employer_city ?>" data-employer_name="employer_name ?>" data-employer_address="employer_address ?>" + data-doc_front="document_image_front ? $a->document_image_front: '' ?>" + data-doc_back="document_image_back ? $a->document_image_back : '' ?>" + data-created_at="created_at ?>" > @@ -115,28 +131,23 @@ data-lastname="lastname ?>" data-firstname="firstname ?>" data-account_number="account_number ?>" + data-customer_number="customer_number ?>" data-iban="iban ?>" - data-swift_code="swift_code ?>" data-status="status ?>" data-reason="reason ?>" data-balance="balance ?>" - data-account_type="account_type ?>" + data-type="type ?>" data-birth_date="birth_date ?>" data-birth_country="birth_country ?>" data-birth_city="birth_city ?>" - data-father_firstname="father_firstname ?>" - data-father_lastname="father_lastname ?>" - data-mother_firstname="mother_firstname ?>" - data-mother_lastname="mother_lastname ?>" - data-marital_name="marital_name ?>" data-nationality="nationality ?>" data-marital_status="marital_status ?>" data-profession="profession ?>" - data-sector_activity="sector_activity ?>" - data-subsector_activity="subsector_activity ?>" - data-tax_number="tax_number ?>" - data-employee_number="employee_number ?>" - data-position="position ?>" + data-employer_city="employer_city ?>" + data-spouse_name="spouse_name ?>" + data-identification_number="identification_number ?>" + data-phone_number="phone_number ?>" + data-niu="niu ?>" data-employer_name="employer_name ?>" data-employer_address="employer_address ?>" data-created_at="created_at ?>" @@ -251,6 +262,9 @@
- @@ -351,11 +407,12 @@
+
+
-
-
-
+
+
@@ -375,11 +432,6 @@
-
-
-
-
-
-
-
+
+ +
+
-
+
@@ -506,13 +560,12 @@ $(document).ready(function () { * ===================================================== */ $(document).on("click", ".open-edit-modal", function () { const fields = [ - "id", "lastname", "firstname", "account_number", "iban", "swift_code", + "id", "lastname", "firstname", "account_number", "iban", "status", "reason", "balance", "birth_date", "birth_country", - "birth_city", "father_firstname", "father_lastname", - "mother_firstname", "mother_lastname", "marital_name", "nationality", - "marital_status", "profession", "sector_activity", - "subsector_activity", "tax_number", "employee_number", "position", - "employer_name", "employer_address", "created_at", "account_type" + "birth_city", "identification_number", "niu", "phone_number", + "spouse_name", "employer_city", "nationality", + "marital_status", "profession","customer_number", + "employer_name", "employer_address", "created_at", "type" ]; fields.forEach(f => { $("#edit_" + f).val($(this).data(f)); @@ -542,31 +595,148 @@ $(document).ready(function () { /* ===================================================== * LOGIQUE MODAL REVIEW (AGENCY & LINK) * ===================================================== */ - $(document).on("click", ".open-review-modal", function () { - let id = $(this).data("id"); - $("#review_id").val(id); - const fields = ["lastname", "firstname", "account_number", "iban", "balance", "status", "profession", "employer_name", "sector_activity", "account_type", "birth_date", "birth_country", "birth_city", "nationality", "marital_status"]; - fields.forEach(f => { $("#view_" + f).text($(this).data(f) || "-"); }); + $(document).on("click", ".open-review-modal", function () { + let id = $(this).data("id"); + $("#review_id").val(id); + + // Reset de l'interface (On remet les boutons par défaut et on vide le motif) + $("#default-actions").show(); + $("#reject-area").hide(); + $("#reject_reason").val(""); + + // Remplissage des infos textes + const fields = ["lastname", "firstname", "account_number", "customer_number", "iban", "balance", "status", "profession", "employer_name", "type", "birth_date", "birth_country", "birth_city", "nationality", "marital_status", "spouse_name", "phone_number", "identification_number", "niu", "employer_address", "employer_city"]; + fields.forEach(f => { $("#view_" + f).text($(this).data(f) || "-"); }); + + // Gestion des documents + let docFront = $(this).data("doc_front"); + let docBack = $(this).data("doc_back"); + $("#hidden_doc_front").val(docFront); + $("#hidden_doc_back").val(docBack); + + // Affichage Image Front + if(docFront && docFront !== "") { + $("#container_doc_front").html(``); + } else { + $("#container_doc_front").html('Aucun document'); + } + + // Affichage Image Back + if(docBack && docBack !== "") { + $("#container_doc_back").html(``); + } else { + $("#container_doc_back").html('Aucun document'); + } }); - function processAgencyRequest(status) { - let id = $("#review_id").val(); - $.ajax({ - url: "", - type: "POST", - data: { id: id, status: status }, - dataType: "json", - success: function (res) { - if (res && res.success === "ok") { - $('#reviewModal').modal('hide'); - toastr.success("Mise à jour effectuée !"); - setTimeout(() => location.reload(), 1500); - } else { toastr.error(res.message || "Erreur"); } - } - }); - } - $("#btn-validate-request").click(function() { processAgencyRequest('active'); }); - $("#btn-reject-request").click(function() { processAgencyRequest('rejected'); }); + /* ===================================================== + * 2. LOGIQUE UI : BASCULEMENT VERS LA ZONE DE REJET + * ===================================================== */ + // Quand on clique sur "REJETER" (le gros bouton rouge) + $("#btn-show-reject-input").click(function() { + $("#default-actions").slideUp(); // On cache les boutons + $("#reject-area").slideDown(); // On affiche le textarea + }); + + // Quand on clique sur "Annuler" (dans la zone de rejet) + $("#btn-cancel-reject").click(function() { + $("#reject-area").slideUp(); + $("#default-actions").slideDown(); + $("#reject_reason").val(""); // On nettoie + }); + + + /* ===================================================== + * 3. ACTION : CONFIRMER LE REJET (Update simple) + * ===================================================== */ + $("#btn-confirm-reject").click(function() { + let id = $("#review_id").val(); + let reason = $("#reject_reason").val().trim(); + + // Validation : Le motif est obligatoire + if(reason === "") { + toastr.warning("Veuillez saisir un motif pour le rejet."); + $("#reject_reason").focus(); + return; + } + + // Désactivation pour éviter double clic + $(this).prop('disabled', true).text('Traitement...'); + + $.ajax({ + url: "", + type: "POST", + data: { + id: id, + status: 'rejected', + reason: reason // On envoie le motif saisi + }, + dataType: "json", + success: function (res) { + if (res && res.success === "ok") { + $('#reviewModal').modal('hide'); + toastr.warning("Demande rejetée avec succès."); + setTimeout(() => location.reload(), 1500); + } else { + toastr.error(res.message || "Erreur lors du rejet."); + $("#btn-confirm-reject").prop('disabled', false).text('Confirmer le rejet'); + } + }, + error: function () { + toastr.error("Erreur serveur (500)."); + $("#btn-confirm-reject").prop('disabled', false).text('Confirmer le rejet'); + } + }); + }); + + + /* ===================================================== + * LOGIQUE DE VALIDATION (AGENCY BANKING) + * ===================================================== */ + + // 1. Fonction pour VALIDER + function validateAgencyRequest() { + let id = $("#review_id").val(); + + // Récupération des documents (stockés dans les inputs cachés lors de l'ouverture du modal) + let docFront = $("#hidden_doc_front").val(); + let docBack = $("#hidden_doc_back").val(); + + // On peut désactiver le bouton pour éviter le double clic + $("#btn-validate-request").prop('disabled', true).html(' Traitement...'); + + $.ajax({ + url: "", // URL SPÉCIFIQUE + type: "POST", + data: { + id: id, + status: 'active', + doc_front: docFront, + doc_back: docBack + }, + dataType: "json", + success: function (res) { + $("#btn-validate-request").prop('disabled', false).html('VALIDER'); + + if (res && res.success === "ok") { + $('#reviewModal').modal('hide'); + toastr.success(res.message || "Demande validée avec succès !"); + setTimeout(() => location.reload(), 1500); + } else { + toastr.error(res.message || "Erreur lors de la validation."); + } + }, + error: function () { + $("#btn-validate-request").prop('disabled', false).html('VALIDER'); + toastr.error("Erreur serveur (500) lors de la validation."); + } + }); + } + + // Clic sur VALIDER + $("#btn-validate-request").click(function() { + validateAgencyRequest(); + }); // Logique Review LINK