From d57808f868b2aa7ed032c45eb47263e93fa40ff6 Mon Sep 17 00:00:00 2001 From: cherif Date: Mon, 5 Jun 2023 14:56:59 +0200 Subject: [PATCH] 05/06/23 - 15h --- src/components/Abonnement.js | 191 ++++++++++++++++++++++--- src/components/CheckOut.js | 17 ++- src/components/Partner.js | 2 +- src/styles/components/_abonnement.scss | 30 +++- 4 files changed, 206 insertions(+), 34 deletions(-) diff --git a/src/components/Abonnement.js b/src/components/Abonnement.js index e9c1081..6c6b496 100644 --- a/src/components/Abonnement.js +++ b/src/components/Abonnement.js @@ -30,6 +30,8 @@ import SendIcon from '@mui/icons-material/Send'; import { confirmAlert } from 'react-confirm-alert'; // Import import { RiAddCircleLine } from "react-icons/ri"; import img_loading_spin from "./../mysy_img/mysy_spin_loading.gif"; +import 'react-tooltip/dist/react-tooltip.css' +import { Tooltip } from 'react-tooltip' function Abonnement(props) { @@ -644,6 +646,15 @@ function Abonnement(props) { const [new_nb_formations, setnew_nb_formations] = useState(); function Change_Partne_Nb_Ftion() { + setcode_promo_code(""); + setcode_promo_type(""); + setcode_promo_valeur(""); + setcode_promo_text_to_display(""); + + sethandleOnblur_Code_Promo_api(""); + sethandleOnblur_Code_Promo_result(""); + sethandleOnblur_Code_Promo_message(""); + setchangepartnb_ftion(true); setnew_nb_formations(parnternbformation); get_production_service_by_pack(); @@ -676,6 +687,14 @@ function Abonnement(props) { } function annule_enreg_new_ftion() { + setcode_promo_code(""); + setcode_promo_type(""); + setcode_promo_valeur(""); + setcode_promo_text_to_display(""); + + sethandleOnblur_Code_Promo_api(""); + sethandleOnblur_Code_Promo_result(""); + sethandleOnblur_Code_Promo_message(""); setchangepartnb_ftion(false); } @@ -775,8 +794,13 @@ function Abonnement(props) { form.append("token", stored_cookie); form.append("periodicite", "mensuel"); - form.append("discount", "0"); + //form.append("discount", "0"); form.append("pack", currentpack); + form.append("discount_code", code_promo_code); + form.append("discount_type", code_promo_type); + form.append("discount_valeur", code_promo_valeur); + form.append("discount_qty", new_nb_formations); + /* /!\ : Important, il faut preciser le nombre d'article envoyé avec ceci : form.append("nb_product", nb_article); @@ -793,12 +817,13 @@ function Abonnement(props) { form.append("0", JSON.stringify({ - "code": currentpack, "prix": packprice, "comment": "nc", "qty": new_nb_formations, "pack_products": prod_service + "code": currentpack, "prix": packprice, "comment": "nc", "qty": new_nb_formations, + "pack_products": prod_service })); //form.append("1", JSON.stringify({ "code": "art_supp", "prix": "120", "comment": "nc" })); - + setLoading(true); var myurl = process.env.REACT_APP_API_URL + "myclass/api/createOrder/"; @@ -838,7 +863,7 @@ function Abonnement(props) { setLoading(false); }); - // setLoading(false); + // setLoading(false); } @@ -954,14 +979,80 @@ function Abonnement(props) { return; } - confirmSNEwAbonnement(); } + const [code_promo_code, setcode_promo_code] = useState(""); + const [code_promo_type, setcode_promo_type] = useState(""); + const [code_promo_valeur, setcode_promo_valeur] = useState(""); + const [code_promo_text_to_display, setcode_promo_text_to_display] = useState(""); + + const [handleOnblur_Code_Promo_api, sethandleOnblur_Code_Promo_api] = useState(""); + const [handleOnblur_Code_Promo_result, sethandleOnblur_Code_Promo_result] = useState(""); + const [handleOnblur_Code_Promo_message, sethandleOnblur_Code_Promo_message] = useState(""); + + const handleOnblur_Code_Promo = (event) => { + + setcode_promo_code(""); + setcode_promo_type(""); + setcode_promo_valeur(""); + setcode_promo_text_to_display(""); + + sethandleOnblur_Code_Promo_api(""); + sethandleOnblur_Code_Promo_result(""); + sethandleOnblur_Code_Promo_message(""); + + + setcode_promo_code(event.target.value); + //console.log(" ### event.target.value = ", event.target.value); + const formData = new FormData(); + const url = process.env.REACT_APP_API_URL + "myclass/api/Get_Given_Code_Promo/"; + formData.append('token', stored_part); + formData.append('code_promo', event.target.value); + + axios.post(url, formData).then(res => { + //console.log(" In getCurrentUserData res.data.status = " + res.data.status); + //console.log(" In getCurrentUserData res.data.message = " + res.data.message); + if (String(res.data.status) === "true") { + + sethandleOnblur_Code_Promo_api("true"); + sethandleOnblur_Code_Promo_result(res.data.message); + + var mycodepromo_data = JSON.parse(res.data.message); + if (mycodepromo_data) { + //console.log(' mycodepromo_data = ', mycodepromo_data); + if (mycodepromo_data.type) { + setcode_promo_type(mycodepromo_data.type); + } + if (mycodepromo_data.valeur) { + setcode_promo_valeur(mycodepromo_data.valeur); + } + + if (String(mycodepromo_data.type).toLocaleLowerCase() === "fix") { + setcode_promo_text_to_display("- " + mycodepromo_data.valeur + " €") + } + else if (String(mycodepromo_data.type).toLocaleLowerCase() === "percent") { + setcode_promo_text_to_display("- " + mycodepromo_data.valeur + " % ") + } + + } + } + else { + + sethandleOnblur_Code_Promo_api("false"); + sethandleOnblur_Code_Promo_message(res.data.message); + } + + }).catch((error) => { + console.warn('Erro handleOnblur_Code_Promo = ', error); + sethandleOnblur_Code_Promo_api("false"); + }) + } + return (
- {isLoading &&
-
+ {isLoading &&
+
} @@ -1011,7 +1102,7 @@ function Abonnement(props) { } {changepartnb_ftion &&
-
+
Mesnuel @@ -1021,7 +1112,7 @@ function Abonnement(props) {
-
+
Nombre :
@@ -1037,7 +1128,7 @@ function Abonnement(props) { />
-
+
Total HT :
@@ -1047,27 +1138,89 @@ function Abonnement(props) {
-
+
+ + + + {/*
+ val_remise_ici +
*/} + + {(!code_promo_text_to_display || String(code_promo_text_to_display)) === "" && +
+ 0 € +
+ } + + {code_promo_text_to_display && String(code_promo_text_to_display) != "" && + +
+ {code_promo_text_to_display} +
+ } + +
+ +
TVA :
-
- {packprice * new_nb_formations * .2} € -
+ {String(handleOnblur_Code_Promo_api) !== "true" &&
+ {(packprice * new_nb_formations * 0.2).toFixed(2)} € +
} + {String(handleOnblur_Code_Promo_api) === "true" && +
+ {String(code_promo_type) === "fix" && } + + {String(code_promo_type) === "percent" && } +
} +
-
+
Total TTC :
-
- {packprice * new_nb_formations * 1.2} € -
+ + {String(handleOnblur_Code_Promo_api) !== "true" && +
+ {(packprice * new_nb_formations * 1.2).toFixed(2)} € +
+ } + {String(handleOnblur_Code_Promo_api) === "true" && +
+ + {String(code_promo_type) === "fix" && } + + {String(code_promo_type) === "percent" && } + +
+ } + +
-
+
diff --git a/src/components/CheckOut.js b/src/components/CheckOut.js index 7150a45..3aff446 100644 --- a/src/components/CheckOut.js +++ b/src/components/CheckOut.js @@ -555,6 +555,9 @@ function CheckOut(props) { form1.append("token", stored_cookie); form1.append("pack", currentpack); form1.append("qty", nb_formations); + form1.append("discount_code", code_promo_code); + form1.append("discount_type", code_promo_type); + form1.append("discount_valeur", code_promo_valeur); fetch(myurl, { method: 'POST', @@ -1299,8 +1302,8 @@ function CheckOut(props) {
{String(handleOnblur_Code_Promo_api) !== "true" &&
- {packprice * nb_formations * 0.2} € + {(packprice * nb_formations * 0.2).toFixed(2)} €
} {String(handleOnblur_Code_Promo_api) === "true" && @@ -1386,7 +1389,7 @@ function CheckOut(props) { {String(handleOnblur_Code_Promo_api) !== "true" &&
- {packprice * nb_formations * 1.2} € + {(packprice * nb_formations * 1.2).toFixed(2)} €
} diff --git a/src/components/Partner.js b/src/components/Partner.js index d01af95..b8acd0a 100644 --- a/src/components/Partner.js +++ b/src/components/Partner.js @@ -564,7 +564,7 @@ const Partner = (props) => { my_lms_url = (JSON.parse(res.data.message).lms_virtualhost_url) + "user_portal.php?recid=" + encodeURIComponent(JSON.parse(res.data.message).lms_part_recid) + "&mysytoken=" + encodeURIComponent(JSON.parse(res.data.message).lms_pwd_mask); - console.log(" ### LMS url = ", my_lms_url); + //console.log(" ### LMS url = ", my_lms_url); setpartner_lms_url(my_lms_url); } diff --git a/src/styles/components/_abonnement.scss b/src/styles/components/_abonnement.scss index 394f582..907d204 100644 --- a/src/styles/components/_abonnement.scss +++ b/src/styles/components/_abonnement.scss @@ -450,14 +450,16 @@ } - .pave_nb_ftion {} - + .pave_nb_ftion { + width: 100% !important; + } .pave_change_ftion { text-align: right; border-left: 2px solid; padding-left: 5px; - width: 50%; + width: 100% !important; + padding-right: 1px; } .pave_btn_enreg_new_nb_ftion { @@ -474,6 +476,9 @@ float: left; } + .block_remise{ + width: 100% !important; + } } @@ -669,14 +674,17 @@ } - .pave_nb_ftion {} + .pave_nb_ftion { + width: 100% !important; + } .pave_change_ftion { text-align: right; border-left: 2px solid; padding-left: 5px; - width: 50%; + width: 100% !important; + padding-right: 3px; } .pave_btn_enreg_new_nb_ftion { @@ -692,7 +700,8 @@ width: 100%; float: left; } - + .block_remise{ + } } @@ -896,13 +905,17 @@ font-size: small; } - .pave_nb_ftion {} + .pave_nb_ftion { + width: 100% !important; + } .pave_change_ftion { text-align: right; border-left: 2px solid; padding-left: 5px; + width: 100% !important; + padding-right: 3px; } .pave_btn_enreg_new_nb_ftion { @@ -918,6 +931,9 @@ float: left; } + .block_remise{ + } + }