diff --git a/src/components/AddPartnerClient.js b/src/components/AddPartnerClient.js index 2a56618..33217b3 100644 --- a/src/components/AddPartnerClient.js +++ b/src/components/AddPartnerClient.js @@ -33,11 +33,14 @@ import { ConsoleView } from "react-device-detect"; import fileDownload from 'js-file-download' import { IoAddCircleOutline, IoCloseCircleOutline } from "react-icons/io5"; import { AiOutlineUserAdd } from "react-icons/ai"; +import PartnerClientActivite from "./PartnerClient_Activite"; const AddParnerClient = (props) => { const history = useHistory(); const [submenu, setsubmenu] = useState(""); + const [current_contact_recid, setcurrent_contact_recid] = useState(""); + const [datamodification, setdatamodification] = useState("0"); const [formedit_mode, setformedit_mode] = useState("0"); @@ -83,6 +86,10 @@ const AddParnerClient = (props) => { const [p_contact_telephone, setcontact_telephone] = useState(""); const [p_contact_telephone_mobile, setp_contact_telephone_mobile] = useState(""); + const [p_contact_fonction, setp_contact_fonction] = useState(""); + const [p_contact_civilite, setp_contact_civilite] = useState(""); + + function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); @@ -216,8 +223,6 @@ const AddParnerClient = (props) => { document.getElementById("submenu_contact").style.background = "#104277"; document.getElementById("submenu_contact").style.color = "white"; - - } async function submenu_activite() { @@ -226,11 +231,11 @@ const AddParnerClient = (props) => { Ceci est super crade, fair eun wait de pour attendre l'afficage avant de desacitcation si on a desactiver, mais bon ... on avance. */ await sleep(5); - /* if (String(formedit_mode_invoice) !== "1") { - Disable_invoice_fields(); - } else { - Enable_invoice_fields(); - }*/ + if (String(formedit_mode_invoice) !== "1") { + //Disable_invoice_fields(); + } else { + //Enable_invoice_fields(); + } document.getElementById("submenu_factures").style.background = "#d8edfc"; document.getElementById("submenu_factures").style.color = "#3b3e40"; @@ -244,8 +249,8 @@ const AddParnerClient = (props) => { document.getElementById("submenu_cmd").style.background = "#d8edfc"; document.getElementById("submenu_cmd").style.color = "#3b3e40"; - document.getElementById("submenu_contact").style.background = "#d8edfc"; - document.getElementById("submenu_contact").style.color = "#3b3e40"; + document.getElementById("submenu_donnee_facturation").style.background = "#d8edfc"; + document.getElementById("submenu_donnee_facturation").style.color = "#3b3e40"; document.getElementById("submenu_donnee_client").style.background = "#d8edfc"; document.getElementById("submenu_donnee_client").style.color = "#3b3e40"; @@ -253,11 +258,15 @@ const AddParnerClient = (props) => { document.getElementById("submenu_donnee_facturation").style.background = "#d8edfc"; document.getElementById("submenu_donnee_facturation").style.color = "#3b3e40"; + document.getElementById("submenu_contact").style.background = "#d8edfc"; + document.getElementById("submenu_contact").style.color = "#3b3e40"; + + + document.getElementById("submenu_activite").style.background = "#104277"; document.getElementById("submenu_activite").style.color = "white"; - } async function submenu_devis() { @@ -365,6 +374,7 @@ const AddParnerClient = (props) => { setformedit_mode_contact("0"); clean_contact_set_values(); setaddcontact("1"); + setcurrent_contact_recid(""); } function Close_Contact() { @@ -375,6 +385,7 @@ const AddParnerClient = (props) => { clean_contact_set_values(); setdatamodification_invoice("0"); setformedit_mode_contact("0"); + setcurrent_contact_recid(""); } @@ -955,125 +966,148 @@ const AddParnerClient = (props) => { } -async function Disable_contact_fields() { + async function Disable_contact_fields() { - await sleep(5); + await sleep(5); + + if (document.getElementsByName("contact_email")) { + document.getElementsByName("contact_email")[0].disabled = true; + document.getElementsByName("contact_email")[0].style.backgroundColor = "#ECEFF1"; + } + + if (document.getElementsByName("contact_nom")) { + document.getElementsByName("contact_nom")[0].disabled = true; + document.getElementsByName("contact_nom")[0].style.backgroundColor = "#ECEFF1"; + } + + if (document.getElementsByName("contact_prenom")) { + document.getElementsByName("contact_prenom")[0].disabled = true; + document.getElementsByName("contact_prenom")[0].style.backgroundColor = "#ECEFF1"; + } + + if (document.getElementsByName("contact_fonction")) { + document.getElementsByName("contact_fonction")[0].disabled = true; + document.getElementsByName("contact_fonction")[0].style.backgroundColor = "#ECEFF1"; + } + + + if (document.getElementsByName("contact_civilite")) { + document.getElementsByName("contact_civilite")[0].disabled = true; + document.getElementsByName("contact_civilite")[0].style.backgroundColor = "#ECEFF1"; + } + + + + if (document.getElementsByName("contact_siret")) { + document.getElementsByName("contact_siret")[0].disabled = true; + document.getElementsByName("contact_siret")[0].style.backgroundColor = "#ECEFF1"; + } + + if (document.getElementsByName("contact_tva")) { + document.getElementsByName("contact_tva")[0].disabled = true; + document.getElementsByName("contact_tva")[0].style.backgroundColor = "#ECEFF1"; + } + + if (document.getElementsByName("contact_adresse")) { + document.getElementsByName("contact_adresse")[0].disabled = true; + document.getElementsByName("contact_adresse")[0].style.backgroundColor = "#ECEFF1"; + } + + if (document.getElementsByName("contact_ville")) { + document.getElementsByName("contact_ville")[0].disabled = true; + document.getElementsByName("contact_ville")[0].style.backgroundColor = "#ECEFF1"; + } + + if (document.getElementsByName("contact_code_postal")) { + document.getElementsByName("contact_code_postal")[0].disabled = true; + document.getElementsByName("contact_code_postal")[0].style.backgroundColor = "#ECEFF1"; + } + + if (document.getElementsByName("contact_pays")) { + document.getElementsByName("contact_pays")[0].disabled = true; + document.getElementsByName("contact_pays")[0].style.backgroundColor = "#ECEFF1"; + } + + if (document.getElementsByName("contact_telephone")) { + document.getElementsByName("contact_telephone")[0].disabled = true; + document.getElementsByName("contact_telephone")[0].style.backgroundColor = "#ECEFF1"; + } + + if (document.getElementsByName("contact_telephone_mobile")) { + document.getElementsByName("contact_telephone_mobile")[0].disabled = true; + document.getElementsByName("contact_telephone_mobile")[0].style.backgroundColor = "#ECEFF1"; + } - if (document.getElementsByName("contact_email")) { - document.getElementsByName("contact_email")[0].disabled = true; - document.getElementsByName("contact_email")[0].style.backgroundColor = "#ECEFF1"; } - if (document.getElementsByName("contact_nom")) { - document.getElementsByName("contact_nom")[0].disabled = true; - document.getElementsByName("contact_nom")[0].style.backgroundColor = "#ECEFF1"; + function Enable_contact_fields() { + if (document.getElementsByName("contact_email")) { + document.getElementsByName("contact_email")[0].disabled = false; + document.getElementsByName("contact_email")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_nom")) { + document.getElementsByName("contact_nom")[0].disabled = false; + document.getElementsByName("contact_nom")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_prenom")) { + document.getElementsByName("contact_prenom")[0].disabled = false; + document.getElementsByName("contact_prenom")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_civilite")) { + document.getElementsByName("contact_civilite")[0].disabled = false; + document.getElementsByName("contact_civilite")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_fonction")) { + document.getElementsByName("contact_fonction")[0].disabled = false; + document.getElementsByName("contact_fonction")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_siret")) { + document.getElementsByName("contact_siret")[0].disabled = false; + document.getElementsByName("contact_siret")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_tva")) { + document.getElementsByName("contact_tva")[0].disabled = false; + document.getElementsByName("contact_tva")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_adresse")) { + document.getElementsByName("contact_adresse")[0].disabled = false; + document.getElementsByName("contact_adresse")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_ville")) { + document.getElementsByName("contact_ville")[0].disabled = false; + document.getElementsByName("contact_ville")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_code_postal")) { + document.getElementsByName("contact_code_postal")[0].disabled = false; + document.getElementsByName("contact_code_postal")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_pays")) { + document.getElementsByName("contact_pays")[0].disabled = false; + document.getElementsByName("contact_pays")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_telephone")) { + document.getElementsByName("contact_telephone")[0].disabled = false; + document.getElementsByName("contact_telephone")[0].style.backgroundColor = "#FFFFFF"; + } + + if (document.getElementsByName("contact_telephone_mobile")) { + document.getElementsByName("contact_telephone_mobile")[0].disabled = false; + document.getElementsByName("contact_telephone_mobile")[0].style.backgroundColor = "#FFFFFF"; + } + } - if (document.getElementsByName("contact_prenom")) { - document.getElementsByName("contact_prenom")[0].disabled = true; - document.getElementsByName("contact_prenom")[0].style.backgroundColor = "#ECEFF1"; - } - - if (document.getElementsByName("contact_siret")) { - document.getElementsByName("contact_siret")[0].disabled = true; - document.getElementsByName("contact_siret")[0].style.backgroundColor = "#ECEFF1"; - } - - if (document.getElementsByName("contact_tva")) { - document.getElementsByName("contact_tva")[0].disabled = true; - document.getElementsByName("contact_tva")[0].style.backgroundColor = "#ECEFF1"; - } - - if (document.getElementsByName("contact_adresse")) { - document.getElementsByName("contact_adresse")[0].disabled = true; - document.getElementsByName("contact_adresse")[0].style.backgroundColor = "#ECEFF1"; - } - - if (document.getElementsByName("contact_ville")) { - document.getElementsByName("contact_ville")[0].disabled = true; - document.getElementsByName("contact_ville")[0].style.backgroundColor = "#ECEFF1"; - } - - if (document.getElementsByName("contact_code_postal")) { - document.getElementsByName("contact_code_postal")[0].disabled = true; - document.getElementsByName("contact_code_postal")[0].style.backgroundColor = "#ECEFF1"; - } - - if (document.getElementsByName("contact_pays")) { - document.getElementsByName("contact_pays")[0].disabled = true; - document.getElementsByName("contact_pays")[0].style.backgroundColor = "#ECEFF1"; - } - - if (document.getElementsByName("contact_telephone")) { - document.getElementsByName("contact_telephone")[0].disabled = true; - document.getElementsByName("contact_telephone")[0].style.backgroundColor = "#ECEFF1"; - } - - if (document.getElementsByName("contact_telephone_mobile")) { - document.getElementsByName("contact_telephone_mobile")[0].disabled = true; - document.getElementsByName("contact_telephone_mobile")[0].style.backgroundColor = "#ECEFF1"; - } - -} - -function Enable_contact_fields() { - if (document.getElementsByName("contact_email")) { - document.getElementsByName("contact_email")[0].disabled = false; - document.getElementsByName("contact_email")[0].style.backgroundColor = "#FFFFFF"; - } - - if (document.getElementsByName("contact_nom")) { - document.getElementsByName("contact_nom")[0].disabled = false; - document.getElementsByName("contact_nom")[0].style.backgroundColor = "#FFFFFF"; - } - - if (document.getElementsByName("contact_prenom")) { - document.getElementsByName("contact_prenom")[0].disabled = false; - document.getElementsByName("contact_prenom")[0].style.backgroundColor = "#FFFFFF"; - } - - if (document.getElementsByName("contact_siret")) { - document.getElementsByName("contact_siret")[0].disabled = false; - document.getElementsByName("contact_siret")[0].style.backgroundColor = "#FFFFFF"; - } - - if (document.getElementsByName("contact_tva")) { - document.getElementsByName("contact_tva")[0].disabled = false; - document.getElementsByName("contact_tva")[0].style.backgroundColor = "#FFFFFF"; - } - - if (document.getElementsByName("contact_adresse")) { - document.getElementsByName("contact_adresse")[0].disabled = false; - document.getElementsByName("contact_adresse")[0].style.backgroundColor = "#FFFFFF"; - } - - if (document.getElementsByName("contact_ville")) { - document.getElementsByName("contact_ville")[0].disabled = false; - document.getElementsByName("contact_ville")[0].style.backgroundColor = "#FFFFFF"; - } - - if (document.getElementsByName("contact_code_postal")) { - document.getElementsByName("contact_code_postal")[0].disabled = false; - document.getElementsByName("contact_code_postal")[0].style.backgroundColor = "#FFFFFF"; - } - - if (document.getElementsByName("contact_pays")) { - document.getElementsByName("contact_pays")[0].disabled = false; - document.getElementsByName("contact_pays")[0].style.backgroundColor = "#FFFFFF"; - } - - if (document.getElementsByName("contact_telephone")) { - document.getElementsByName("contact_telephone")[0].disabled = false; - document.getElementsByName("contact_telephone")[0].style.backgroundColor = "#FFFFFF"; - } - - if (document.getElementsByName("contact_telephone_mobile")) { - document.getElementsByName("contact_telephone_mobile")[0].disabled = false; - document.getElementsByName("contact_telephone_mobile")[0].style.backgroundColor = "#FFFFFF"; - } - -} - function confirm_add_user() { confirmAlert({ @@ -1572,25 +1606,29 @@ function Enable_contact_fields() { props.close_detail_client(); } - function retour_liste_contact(){ + function retour_liste_contact() { setaddcontact("0"); } -function clean_contact_set_values(){ - setp_contact_email(""); - setp_contact_nom(""); - setp_contact_prenom(""); - setcontact_siret(""); - setcontact_tva(""); - setcontact_adresse(""); - setcontact_ville(""); - setcontact_code_postal(""); - setcontact_pays(""); + function clean_contact_set_values() { + setp_contact_email(""); + setp_contact_nom(""); + setp_contact_prenom(""); + setcontact_siret(""); + setcontact_tva(""); + setcontact_adresse(""); + setcontact_ville(""); + setcontact_code_postal(""); + setcontact_pays(""); - setcontact_telephone(""); - setp_contact_telephone_mobile("") -} + setcontact_telephone(""); + setp_contact_telephone_mobile(""); + + setp_contact_fonction(""); + setp_contact_civilite(""); + + } function clear_contact_fields() { if (document.getElementsByName("contact_email")) { @@ -1652,9 +1690,22 @@ function clean_contact_set_values(){ form.append("token", stored_cookie); // Recupeation des données à enregister - form.append("related_collection", "partner_client"); - form.append("related_collection_owner_email", p_client_email); + var myurl = ""; + if (current_contact_recid && String(current_contact_recid).length > 3) { + // Il s'agit d'un mise à jour. on a une valeur dans le current_activite_recid + myurl = process.env.REACT_APP_API_URL + "myclass/api/Update_Contact/"; + form.append("contact_recid", current_contact_recid); + + } else { + // Il s'agit d'un ajout d'une nouvelle activité. on a rien dans le current_activite_recid + myurl = process.env.REACT_APP_API_URL + "myclass/api/Add_activite/"; + form.append("related_collection", "partner_client"); + form.append("related_collection_owner_email", p_client_email); + } + + + console.log(" ### current_contact_recid = ", current_contact_recid, " myurl = ", myurl) // Données de contact du client du partner var contact_email = "" @@ -1675,6 +1726,21 @@ function clean_contact_set_values(){ } form.append("prenom", contact_prenom); + + var contact_fonction = "" + if (document.getElementsByName("contact_fonction")) { + contact_fonction = document.getElementsByName("contact_fonction")[0].value; + } + form.append("fonction", contact_fonction); + + var contact_civilite = "" + if (document.getElementsByName("contact_civilite")) { + contact_civilite = document.getElementsByName("contact_civilite")[0].value; + } + form.append("civilite", contact_civilite); + + + var contact_siret = "" if (document.getElementsByName("contact_siret")) { contact_siret = document.getElementsByName("contact_siret")[0].value; @@ -1728,8 +1794,6 @@ function clean_contact_set_values(){ form.append("telephone_mobile", contact_telephone_mobile); - var myurl = process.env.REACT_APP_API_URL + "myclass/api/Add_Contact/"; - axios.post(myurl, form).then(res => { if (String(res.data.status) === String("true")) { //console.log(" In recordPartnerClient_Contact_Data res.data.status = " + res.data.status); @@ -1760,8 +1824,8 @@ function clean_contact_set_values(){ }).catch((error) => { console.warn('Not good man :( recordPartnerClient_Contact_Data = ', error); setrecordPartnerClient_Contact_Data_result("false"); - setrecordPartnerClient_Contact_Data_message(" Impossible de recuperer les informations du client") - alert(" Impossible de recuperer les informations du client"); + setrecordPartnerClient_Contact_Data_message(" Impossible d'enregistrer les doonées du contact") + alert(" Impossible d'enregistrer les doonées du contact"); }) } @@ -1859,8 +1923,27 @@ function clean_contact_set_values(){ else setp_contact_telephone_mobile(""); + + if (mylocalclient_contact.fonction) + setp_contact_fonction(mylocalclient_contact.fonction); + else + setp_contact_fonction(""); + + if (mylocalclient_contact.civilite) + setp_contact_civilite(mylocalclient_contact.civilite); + else + setp_contact_civilite(""); + + + + + if (mylocalclient_contact.recid) + setcurrent_contact_recid(mylocalclient_contact.recid); + else + setcurrent_contact_recid(""); + } - + Disable_contact_fields(); @@ -1882,8 +1965,8 @@ function clean_contact_set_values(){ }).catch((error) => { console.warn('Not good man :( Display_Part_Client_Contact = ', error); setDisplay_Part_Client_Contact_result("false"); - setDisplay_Part_Client_Contact_message(" Impossible de recuperer les informations du client") - alert(" Impossible de recuperer les informations du client"); + setDisplay_Part_Client_Contact_message(" Impossible de recuperer les detail du contact") + alert(" Impossible de recuperer les details du contact"); }) } @@ -2082,7 +2165,6 @@ function clean_contact_set_values(){ } - {String(props.new_customer) !== "1" &&