import React, { useRef, useState, useEffect } from "react";
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem';
import { confirmAlert } from 'react-confirm-alert'; // Import
import 'react-confirm-alert/src/react-confirm-alert.css'; // Import css
import Button from '@mui/material/Button';
import axios from "axios";
import DeleteIcon from '@mui/icons-material/Delete';
import { getCookie, setCookie } from 'react-use-cookie';
import { Alert } from "@mui/material";
import { AiTwotoneEdit, AiTwotoneSave } from "react-icons/ai";
import profileimg from "../mysy_img/MYSY-profil-2.png";
import Abonnement from "./Abonnement";
import { ConstructionOutlined, PropaneSharp } from "@mui/icons-material";
import { useHistory } from "react-router-dom";
import CheckOut from "./CheckOut";

import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
import { RichTextEditor } from '@mantine/rte';
import { Editor } from '@tinymce/tinymce-react';
import { IoArrowUndoCircle } from "react-icons/io5";
import { GrUserAdmin, GrOrderedList } from "react-icons/gr";
import parse from 'html-react-parser';

import 'react-tooltip/dist/react-tooltip.css'
import { Tooltip } from 'react-tooltip'

import GestionAdministrative from "./GestionAdministrative";
import { IoMdAddCircle, IoIosRemoveCircleOutline } from "react-icons/io";
import { Fab } from "@material-ui/core";
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");

    const [datamodification_invoice, setdatamodification_invoice] = useState("0");
    const [formedit_mode_invoice, setformedit_mode_invoice] = useState("0");

    const [datamodification_contact, setdatamodification_contact] = useState("0");
    const [formedit_mode_contact, setformedit_mode_contact] = useState("0");

    const [p_client_email, setclient_email] = useState("");
    const [p_client_nom, setclient_nom] = useState("");

    const [p_client_raison_sociale, setclient_raison_sociale] = useState("");
    const [p_client_siret, setclient_siret] = useState("");
    const [p_client_tva, setclient_tva] = useState("");
    const [p_client_adresse, setclient_adresse] = useState("");
    const [p_client_ville, setclient_ville] = useState("");
    const [p_client_code_postal, setclient_code_postal] = useState("");
    const [p_client_pays, setclient_pays] = useState("");
    const [p_client_telephone, setclient_telephone] = useState("");
    const [p_client_website, setclient_website] = useState("");

    // Données de facturation
    const [p_client_invoice_email, setclient_invoice_email] = useState("");
    const [p_client_invoice_nom, setclient_invoice_nom] = useState("");
    const [p_client_invoice_siret, setclient_invoice_siret] = useState("");
    const [p_client_invoice_tva, setclient_invoice_tva] = useState("");
    const [p_client_invoice_adresse, setclient_invoice_adresse] = useState("");
    const [p_client_invoice_ville, setclient_invoice_ville] = useState("");
    const [p_client_invoice_code_postal, setclient_invoice_code_postal] = useState("");
    const [p_client_invoice_pays, setclient_invoice_pays] = useState("");

    // Données contact
    const [p_contact_email, setp_contact_email] = useState("");
    const [p_contact_nom, setp_contact_nom] = useState("");
    const [p_contact_prenom, setp_contact_prenom] = useState("");
    const [p_contact_siret, setcontact_siret] = useState("");
    const [p_contact_tva, setcontact_tva] = useState("");
    const [p_contact_adresse, setcontact_adresse] = useState("");
    const [p_contact_ville, setcontact_ville] = useState("");
    const [p_contact_code_postal, setcontact_code_postal] = useState("");
    const [p_contact_pays, setcontact_pays] = useState("");
    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));
    }

    const [importmessage, setimportmessage] = useState("");
    async function submenu_donnee_client() {
        setsubmenu("submenu_donnee_client");
        /*
       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) !== "1") {
            Disable_fields();
        } else {
            Enable_fields();
        }

        document.getElementById("submenu_factures").style.background = "#d8edfc";
        document.getElementById("submenu_factures").style.color = "#3b3e40";

        document.getElementById("submenu_stagiaires").style.background = "#d8edfc";
        document.getElementById("submenu_stagiaires").style.color = "#3b3e40";

        document.getElementById("submenu_devis").style.background = "#d8edfc";
        document.getElementById("submenu_devis").style.color = "#3b3e40";

        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_activite").style.background = "#d8edfc";
        document.getElementById("submenu_activite").style.color = "#3b3e40";

        document.getElementById("submenu_donnee_client").style.background = "#d8edfc";
        document.getElementById("submenu_donnee_client").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 = "#104277";
        document.getElementById("submenu_donnee_client").style.color = "white";

    }



    async function submenu_donnee_facturation() {
        setsubmenu("submenu_donnees_facturation");
        /*
        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();
        }

        document.getElementById("submenu_factures").style.background = "#d8edfc";
        document.getElementById("submenu_factures").style.color = "#3b3e40";

        document.getElementById("submenu_stagiaires").style.background = "#d8edfc";
        document.getElementById("submenu_stagiaires").style.color = "#3b3e40";

        document.getElementById("submenu_devis").style.background = "#d8edfc";
        document.getElementById("submenu_devis").style.color = "#3b3e40";

        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_activite").style.background = "#d8edfc";
        document.getElementById("submenu_activite").style.color = "#3b3e40";

        document.getElementById("submenu_donnee_client").style.background = "#d8edfc";
        document.getElementById("submenu_donnee_client").style.color = "#3b3e40";

        document.getElementById("submenu_donnee_facturation").style.background = "#d8edfc";
        document.getElementById("submenu_donnee_facturation").style.color = "#3b3e40";

        document.getElementById("submenu_donnee_facturation").style.background = "#104277";
        document.getElementById("submenu_donnee_facturation").style.color = "white";



    }

    async function submenu_contact() {
        setsubmenu("submenu_contact");
        /*
        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();
        }*/

        document.getElementById("submenu_factures").style.background = "#d8edfc";
        document.getElementById("submenu_factures").style.color = "#3b3e40";

        document.getElementById("submenu_stagiaires").style.background = "#d8edfc";
        document.getElementById("submenu_stagiaires").style.color = "#3b3e40";

        document.getElementById("submenu_devis").style.background = "#d8edfc";
        document.getElementById("submenu_devis").style.color = "#3b3e40";

        document.getElementById("submenu_cmd").style.background = "#d8edfc";
        document.getElementById("submenu_cmd").style.color = "#3b3e40";

        document.getElementById("submenu_donnee_facturation").style.background = "#d8edfc";
        document.getElementById("submenu_donnee_facturation").style.color = "#3b3e40";

        document.getElementById("submenu_activite").style.background = "#d8edfc";
        document.getElementById("submenu_activite").style.color = "#3b3e40";

        document.getElementById("submenu_donnee_client").style.background = "#d8edfc";
        document.getElementById("submenu_donnee_client").style.color = "#3b3e40";

        document.getElementById("submenu_donnee_facturation").style.background = "#d8edfc";
        document.getElementById("submenu_donnee_facturation").style.color = "#3b3e40";


        document.getElementById("submenu_contact").style.background = "#104277";
        document.getElementById("submenu_contact").style.color = "white";

    }

    async function submenu_activite() {

        setsubmenu("submenu_activite");
        /*
        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();
        }

        document.getElementById("submenu_factures").style.background = "#d8edfc";
        document.getElementById("submenu_factures").style.color = "#3b3e40";

        document.getElementById("submenu_stagiaires").style.background = "#d8edfc";
        document.getElementById("submenu_stagiaires").style.color = "#3b3e40";

        document.getElementById("submenu_devis").style.background = "#d8edfc";
        document.getElementById("submenu_devis").style.color = "#3b3e40";

        document.getElementById("submenu_cmd").style.background = "#d8edfc";
        document.getElementById("submenu_cmd").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";

        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() {
        setsubmenu("submenu_devis");
        /*
        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);
    }

    async function submenu_cmd() {
        setsubmenu("submenu_cmd");
        /*
        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);
    }

    async function submenu_factures() {
        setsubmenu("submenu_factures");
        /*
        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);
    }


    async function submenu_stagiaires() {
        setsubmenu("submenu_stagiaires");
        /*
        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);
    }

    function DataUpdated() {
        setdatamodification("1");
    }

    function DataEditMode() {
        setformedit_mode("1");
        Enable_fields();
    }

    function AnnulerEdit() {
        setformedit_mode("0");
        setdatamodification("0");
        Disable_fields();
        clear_fields();
        fillfield_Only_Main_Data(props.client_mail);

    }

    function DataUpdated_Invoice_Data() {
        setdatamodification_invoice("1");
    }

    function DataEditMode_Invoice_Data() {
        setformedit_mode_invoice("1");
        Enable_invoice_fields();
    }



    function DataUpdated_Contact_Data() {
        setdatamodification_contact("1");
    }

    function DataEditMode_Contact_Data() {
        setformedit_mode_contact("1");
        Enable_contact_fields();
    }


    function AnnulerEdit_Invoice_Data() {
        setformedit_mode_invoice("0");
        setdatamodification_invoice("0");
        Disable_invoice_fields();
        clear_invoice_fields();
        fillfield_Invoice_Data(props.client_mail);
    }


    function SetTabFocus() {

        document.getElementById("submenu_donnee_client").style.background = "#d8edfc";
        document.getElementById("submenu_donnee_client").style.color = "#3b3e40";
        document.getElementById("submenu_donnee_facturation").style.background = "#d8edfc";
        document.getElementById("submenu_donnee_facturation").style.color = "#3b3e40";


        if (String(submenu) === "submenu_donnee_client") {
            document.getElementById("submenu_donnee_client").style.background = "#104277";
            document.getElementById("submenu_donnee_client").style.color = "white";
        }
        else if (String(submenu) === "submenu_donnees_facturation") {
            document.getElementById("submenu_donnee_facturation").style.background = "#104277";
            document.getElementById("submenu_donnee_facturation").style.color = "white";
        }
    }

    const [addcontact, setaddcontact] = useState("0");
    function Add_Contact() {
        setdatamodification_contact("0");
        setformedit_mode_contact("0");
        clean_contact_set_values();
        setaddcontact("1");
        setcurrent_contact_recid("");
    }

    function Close_Contact() {
        setaddcontact("0");
        setdatamodification_contact("0");
        setformedit_mode_contact("0");
        clear_contact_fields();
        clean_contact_set_values();
        setdatamodification_invoice("0");
        setformedit_mode_contact("0");
        setcurrent_contact_recid("");
    }


    useEffect(() => {


        if (String(props.new_customer) !== "1") {
            setformedit_mode("0");
            setformedit_mode_invoice("0");

            submenu_donnee_client();
            fillfield(props.client_mail);

            setdatamodification("0");
            setdatamodification_invoice("0");

            Get_List_Contact_Of_client_Part();

            window.scrollTo(0, 0);
        } else {
            setformedit_mode("1");
            setformedit_mode_invoice("1");

        }


    }, [props.client_mail,]);


    const [fillfield_api, setfillfield_api] = useState("");
    const [fillfield_result, setfillfield_result] = useState("");
    const [fillfield_message, setfillfield_message] = useState("");
    function fillfield(cust_email) {

        var val = cust_email;

        var form = new FormData();

        const stored_cookie = getCookie('tokenmysypart');
        form.append("token", stored_cookie);
        form.append("email", val);

        var myurl = process.env.REACT_APP_API_URL + "myclass/api/Get_Given_Partner_Client/";

        axios.post(myurl, form).then(res => {
            if (String(res.data.status) === String("true")) {
                //console.log(" In fillfield  res.data.status = " + res.data.status);
                //console.log(" In fillfield  res.data.message  = " + res.data.message);
                setfillfield_api("true");
                setfillfield_result(res.data.message);
                var mylocalclient = JSON.parse(res.data.message);


                if (mylocalclient) {
                    document.getElementsByName("client_email")[0].value = mylocalclient.email;
                    document.getElementsByName("client_nom")[0].value = mylocalclient.nom;
                    setclient_nom(mylocalclient.nom);
                    setclient_email(mylocalclient.email);


                    if (mylocalclient.raison_sociale) {
                        setclient_raison_sociale(mylocalclient.raison_sociale);
                    } else {
                        setclient_raison_sociale("");
                    }

                    if (mylocalclient.adr_adresse)
                        setclient_adresse(mylocalclient.adr_adresse);
                    else
                        setclient_adresse("");


                    if (mylocalclient.adr_ville)
                        setclient_ville(mylocalclient.adr_ville);
                    else
                        setclient_ville("");

                    if (mylocalclient.adr_pays)
                        setclient_pays(mylocalclient.adr_pays);
                    else
                        setclient_pays("");

                    if (mylocalclient.siret)
                        setclient_siret(mylocalclient.siret);
                    else
                        setclient_siret("");

                    if (mylocalclient.tva)
                        setclient_tva(mylocalclient.tva);
                    else
                        setclient_tva("");

                    if (mylocalclient.website)
                        setclient_website(mylocalclient.website);
                    else
                        setclient_website("");

                    if (mylocalclient.telephone)
                        setclient_telephone(mylocalclient.telephone);
                    else
                        setclient_telephone("");

                    // Remplissage des doonées de facturation
                    if (mylocalclient.invoice_email)
                        setclient_invoice_email(mylocalclient.invoice_email);
                    else
                        setclient_invoice_email("");

                    if (mylocalclient.invoice_nom)
                        setclient_invoice_nom(mylocalclient.invoice_nom);
                    else
                        setclient_invoice_nom("");


                    if (mylocalclient.invoice_siret)
                        setclient_invoice_siret(mylocalclient.invoice_siret);
                    else
                        setclient_invoice_siret("");

                    if (mylocalclient.invoice_tva)
                        setclient_invoice_tva(mylocalclient.invoice_tva);
                    else
                        setclient_invoice_tva("");

                    if (mylocalclient.invoice_adresse)
                        setclient_invoice_adresse(mylocalclient.invoice_adresse);
                    else
                        setclient_invoice_adresse("");

                    if (mylocalclient.invoice_ville)
                        setclient_invoice_ville(mylocalclient.invoice_ville);
                    else
                        setclient_invoice_ville("");

                    if (mylocalclient.invoice_code_postal)
                        setclient_invoice_code_postal(mylocalclient.invoice_code_postal);
                    else
                        setclient_invoice_code_postal("");

                    if (mylocalclient.invoice_pays)
                        setclient_invoice_pays(mylocalclient.invoice_pays);
                    else
                        setclient_invoice_pays("");

                    setdatamodification("0");
                    setdatamodification_invoice("0");

                    Disable_fields();
                    //Disable_invoice_fields();
                }
            }
            else if (String(res.data.status) === String("Err_Connexion")) {
                alert('Erreur: ' + res.data.message);
                history.push("/Connexion");
                return;
            }
            else {

                setfillfield_api("false");
                setfillfield_message(res.data.message);
            }


        }).catch((error) => {
            console.warn('Not good man :( fillfield = ', error);
            setfillfield_result("false");
            setfillfield_message(" Impossible de recuperer les informations du client")

        })
    }


    const [fillfield_Invoice_Data_api, setfillfield_Invoice_Data_api] = useState("");
    const [fillfield_Invoice_Data_result, setfillfield_Invoice_Data_result] = useState("");
    const [fillfield_Invoice_Data_message, setfillfield_Invoice_Data_message] = useState("");
    function fillfield_Invoice_Data(cust_email) {

        var val = cust_email;

        var form = new FormData();

        const stored_cookie = getCookie('tokenmysypart');
        form.append("token", stored_cookie);
        form.append("email", p_client_email);
        form.append("nom", p_client_nom);

        var myurl = process.env.REACT_APP_API_URL + "myclass/api/Get_Given_Partner_Client/";

        axios.post(myurl, form).then(res => {
            if (String(res.data.status) === String("true")) {
                //console.log(" In fillfield_Invoice_Data  res.data.status = " + res.data.status);
                //console.log(" In fillfield_Invoice_Data  res.data.message  = " + res.data.message);
                setfillfield_Invoice_Data_api("true");
                setfillfield_Invoice_Data_result(res.data.message);
                var mylocalclient = JSON.parse(res.data.message);


                if (mylocalclient) {

                    // Remplissage des doonées de facturation
                    if (mylocalclient.invoice_email)
                        setclient_invoice_email(mylocalclient.invoice_email);
                    else
                        setclient_invoice_email("");

                    if (mylocalclient.invoice_nom)
                        setclient_invoice_nom(mylocalclient.invoice_nom);
                    else
                        setclient_invoice_nom("");

                    if (mylocalclient.invoice_siret)
                        setclient_invoice_siret(mylocalclient.invoice_siret);
                    else
                        setclient_invoice_siret("");

                    if (mylocalclient.invoice_tva)
                        setclient_invoice_tva(mylocalclient.invoice_tva);
                    else
                        setclient_invoice_tva("");

                    if (mylocalclient.invoice_adresse)
                        setclient_invoice_adresse(mylocalclient.invoice_adresse);
                    else
                        setclient_invoice_adresse("");

                    if (mylocalclient.invoice_ville)
                        setclient_invoice_ville(mylocalclient.invoice_ville);
                    else
                        setclient_invoice_ville("");

                    if (mylocalclient.invoice_code_postal)
                        setclient_invoice_code_postal(mylocalclient.invoice_code_postal);
                    else
                        setclient_invoice_code_postal("");

                    if (mylocalclient.invoice_pays)
                        setclient_invoice_pays(mylocalclient.invoice_pays);
                    else
                        setclient_invoice_pays("");

                    Disable_invoice_fields();
                }
            }
            else if (String(res.data.status) === String("Err_Connexion")) {
                alert('Erreur: ' + res.data.message);
                history.push("/Connexion");
                return;
            }
            else {

                setfillfield_Invoice_Data_api("false");
                setfillfield_Invoice_Data_message(res.data.message);
            }


        }).catch((error) => {
            console.warn('Not good man :( fillfield_Invoice_Data = ', error);
            setfillfield_Invoice_Data_result("false");
            setfillfield_Invoice_Data_message(" Impossible de recuperer les informations du client")

        })
    }

    const [fillfield_Only_Main_Data_api, setfillfield_Only_Main_Data_api] = useState("");
    const [fillfield_Only_Main_Data_result, setfillfield_Only_Main_Data_result] = useState("");
    const [fillfield_Only_Main_Data_message, setfillfield_Only_Main_Data_message] = useState("");
    function fillfield_Only_Main_Data(cust_email) {

        var val = cust_email;

        var form = new FormData();

        const stored_cookie = getCookie('tokenmysypart');
        form.append("token", stored_cookie);
        form.append("email", val);

        var myurl = process.env.REACT_APP_API_URL + "myclass/api/Get_Given_Partner_Client/";

        axios.post(myurl, form).then(res => {
            if (String(res.data.status) === String("true")) {
                //console.log(" In fillfield_Only_Main_Data  res.data.status = " + res.data.status);
                //console.log(" In fillfield_Only_Main_Data  res.data.message  = " + res.data.message);
                setfillfield_Only_Main_Data_api("true");
                setfillfield_Only_Main_Data_result(res.data.message);
                var mylocalclient = JSON.parse(res.data.message);


                if (mylocalclient) {

                    if (mylocalclient.raison_sociale) {
                        setclient_raison_sociale(mylocalclient.raison_sociale);
                    } else {
                        setclient_raison_sociale("");
                    }

                    if (mylocalclient.adr_adresse)
                        setclient_adresse(mylocalclient.adr_adresse);
                    else
                        setclient_adresse("");


                    if (mylocalclient.adr_ville)
                        setclient_ville(mylocalclient.adr_ville);
                    else
                        setclient_ville("");

                    if (mylocalclient.adr_pays)
                        setclient_pays(mylocalclient.adr_pays);
                    else
                        setclient_pays("");

                    if (mylocalclient.siret)
                        setclient_siret(mylocalclient.siret);
                    else
                        setclient_siret("");

                    if (mylocalclient.tva)
                        setclient_tva(mylocalclient.tva);
                    else
                        setclient_tva("");

                    if (mylocalclient.website)
                        setclient_website(mylocalclient.website);
                    else
                        setclient_website("");

                    if (mylocalclient.telephone)
                        setclient_telephone(mylocalclient.telephone);
                    else
                        setclient_telephone("");


                    Disable_fields();

                }
            }
            else if (String(res.data.status) === String("Err_Connexion")) {
                alert('Erreur: ' + res.data.message);
                history.push("/Connexion");
                return;
            }
            else {

                setfillfield_Only_Main_Data_api("false");
                setfillfield_Only_Main_Data_message(res.data.message);
            }


        }).catch((error) => {
            console.warn('Not good man :( fillfield_Only_Main_Data = ', error);
            setfillfield_Only_Main_Data_result("false");
            setfillfield_Only_Main_Data_message(" Impossible de recuperer les informations du client")

        })
    }


    const [Get_List_Contact_Of_client_Part_api, setGet_List_Contact_Of_client_Part_api] = useState();
    const [Get_List_Contact_Of_client_Part_message, setGet_List_Contact_Of_client_Part_message] = useState();
    const [Get_List_Contact_Of_client_Part_result, setGet_List_Contact_Of_client_Part_result] = useState();
    function Get_List_Contact_Of_client_Part(event) {

        var form = new FormData();
        const stored_cookie = getCookie('tokenmysypart');
        const related_collection = "partner_client"


        form.append("token", stored_cookie);
        form.append("related_collection", related_collection);
        form.append("related_collection_owner_email", props.client_mail);


        var myurl = process.env.REACT_APP_API_URL + "myclass/api/Get_List_Entity_Contact/";

        axios.post(myurl, form).then(res => {
            //console.log(" In Get_List_Contact_Of_client_Part  res.data.status = " + res.data.status);
            //console.log(" In Get_List_Contact_Of_client_Part  res.data.message r_class = " + res.data.message);

            if (String(res.data.status) === String("true")) {
                setGet_List_Contact_Of_client_Part_api("true");
                setGet_List_Contact_Of_client_Part_result(res.data.message);

            }
            else if (String(res.data.status) === String("Err_Connexion")) {
                alert('Erreur: ' + res.data.message);
                history.push("/Connexion");
            }
            else {
                setGet_List_Contact_Of_client_Part_api("false");
                setGet_List_Contact_Of_client_Part_message(res.data.message);
            }

        }).catch((error) => {
            console.warn('Not good man :( Get_List_Contact_Of_client_Part = ', error);
            setGet_List_Contact_Of_client_Part_api("false");
            //setmyApimyApiMessage("")
        })
    }


    function clear_fields() {
        if (document.getElementsByName("client_email")) {
            document.getElementsByName("client_email")[0].value = "";
        }

        if (document.getElementsByName("client_nom")) {
            document.getElementsByName("client_nom")[0].value = "";
        }

        if (document.getElementsByName("client_raison_sociale")) {
            document.getElementsByName("client_raison_sociale")[0].value = "";
        }

        if (document.getElementsByName("client_adresse")) {
            document.getElementsByName("client_adresse")[0].value = "";
        }

        if (document.getElementsByName("client_ville")) {
            document.getElementsByName("client_ville")[0].value = "";
        }

        if (document.getElementsByName("client_pays")) {
            document.getElementsByName("client_pays")[0].value = "";
        }

        if (document.getElementsByName("client_email")) {
            document.getElementsByName("client_email")[0].value = "";
        }

        if (document.getElementsByName("client_siret")) {
            document.getElementsByName("client_siret")[0].value = "";
        }

        if (document.getElementsByName("client_tva")) {
            document.getElementsByName("client_tva")[0].value = "";
        }

        if (document.getElementsByName("client_website")) {
            document.getElementsByName("client_website")[0].value = "";
        }

        if (document.getElementsByName("client_code_postal")) {
            document.getElementsByName("client_code_postal")[0].value = "";
        }

        if (document.getElementsByName("client_telephone")) {
            document.getElementsByName("client_telephone")[0].value = "";
        }

    }

    function Disable_fields() {
        if (document.getElementsByName("client_email")) {
            document.getElementsByName("client_email")[0].disabled = true;
            document.getElementsByName("client_email")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_nom")) {
            document.getElementsByName("client_nom")[0].disabled = true;
            document.getElementsByName("client_nom")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_raison_sociale")) {
            document.getElementsByName("client_raison_sociale")[0].disabled = true;
            document.getElementsByName("client_raison_sociale")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_adresse")) {
            document.getElementsByName("client_adresse")[0].disabled = true;
            document.getElementsByName("client_adresse")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_ville")) {
            document.getElementsByName("client_ville")[0].disabled = true;
            document.getElementsByName("client_ville")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_pays")) {
            document.getElementsByName("client_pays")[0].disabled = true;
            document.getElementsByName("client_pays")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_email")) {
            document.getElementsByName("client_email")[0].disabled = true;
            document.getElementsByName("client_email")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_siret")) {
            document.getElementsByName("client_siret")[0].disabled = true;
            document.getElementsByName("client_siret")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_tva")) {
            document.getElementsByName("client_tva")[0].disabled = true;
            document.getElementsByName("client_tva")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_website")) {
            document.getElementsByName("client_website")[0].disabled = true;
            document.getElementsByName("client_website")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_code_postal")) {
            document.getElementsByName("client_code_postal")[0].disabled = true;
            document.getElementsByName("client_code_postal")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_telephone")) {
            document.getElementsByName("client_telephone")[0].disabled = true;
            document.getElementsByName("client_telephone")[0].style.backgroundColor = "#ECEFF1";
        }


    }

    function Enable_fields() {
        if (document.getElementsByName("client_email")) {
            document.getElementsByName("client_email")[0].disabled = false;
            document.getElementsByName("client_email")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_nom")) {
            document.getElementsByName("client_nom")[0].disabled = false;
            document.getElementsByName("client_nom")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_raison_sociale")) {
            document.getElementsByName("client_raison_sociale")[0].disabled = false;
            document.getElementsByName("client_raison_sociale")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_adresse")) {
            document.getElementsByName("client_adresse")[0].disabled = false;
            document.getElementsByName("client_adresse")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_ville")) {
            document.getElementsByName("client_ville")[0].disabled = false;
            document.getElementsByName("client_ville")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_pays")) {
            document.getElementsByName("client_pays")[0].disabled = false;
            document.getElementsByName("client_pays")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_email")) {
            document.getElementsByName("client_email")[0].disabled = false;
            document.getElementsByName("client_email")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_siret")) {
            document.getElementsByName("client_siret")[0].disabled = false;
            document.getElementsByName("client_siret")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_tva")) {
            document.getElementsByName("client_tva")[0].disabled = false;
            document.getElementsByName("client_tva")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_website")) {
            document.getElementsByName("client_website")[0].disabled = false;
            document.getElementsByName("client_website")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_code_postal")) {
            document.getElementsByName("client_code_postal")[0].disabled = false;
            document.getElementsByName("client_code_postal")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_telephone")) {
            document.getElementsByName("client_telephone")[0].disabled = false;
            document.getElementsByName("client_telephone")[0].style.backgroundColor = "#FFFFFF";
        }


    }


    async function Disable_contact_fields() {

        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";
        }

    }

    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";
        }

    }


    function confirm_add_user() {
        confirmAlert({
            title: '',
            message: 'Confirmez la creation du client',
            buttons: [
                {
                    label: 'Oui',
                    onClick: () => Add_New_PartnerClient()
                },
                {
                    label: 'Non',
                    onClick: () => { return }
                }
            ]
        });
    }



    const [Add_New_PartnerClient_api, setAdd_New_PartnerClient_api] = useState("");
    const [Add_New_PartnerClient_result, setAdd_New_PartnerClient_result] = useState("");
    const [Add_New_PartnerClient_message, setAdd_New_PartnerClient_message] = useState("");
    function Add_New_PartnerClient(event) {


        var form = new FormData();

        const stored_cookie = getCookie('tokenmysypart');
        form.append("token", stored_cookie);

        // Recupeation des données à enregister

        var client_email = ""
        if (document.getElementsByName("client_email")) {
            client_email = document.getElementsByName("client_email")[0].value;
        }
        form.append("email", client_email);


        var client_nom = ""
        if (document.getElementsByName("client_nom")) {
            client_nom = document.getElementsByName("client_nom")[0].value;
        }
        form.append("nom", client_nom);

        var client_raison_sociale = ""
        if (document.getElementsByName("client_raison_sociale")) {
            client_raison_sociale = document.getElementsByName("client_raison_sociale")[0].value;
        }
        form.append("raison_sociale", client_raison_sociale);

        var client_adresse = ""
        if (document.getElementsByName("client_adresse")) {
            client_adresse = document.getElementsByName("client_adresse")[0].value;
        }
        form.append("adr_adresse", client_adresse);

        var client_code_postal = ""
        if (document.getElementsByName("client_code_postal")) {
            client_code_postal = document.getElementsByName("client_code_postal")[0].value;
        }
        form.append("adr_code_postal", client_code_postal);

        var client_ville = ""
        if (document.getElementsByName("client_ville")) {
            client_ville = document.getElementsByName("client_ville")[0].value;
        }
        form.append("adr_ville", client_ville);

        var client_pays = ""
        if (document.getElementsByName("client_pays")) {
            client_pays = document.getElementsByName("client_pays")[0].value;
        }
        form.append("adr_pays", client_pays);



        var client_telephone = ""
        if (document.getElementsByName("client_telephone")) {
            client_telephone = document.getElementsByName("client_telephone")[0].value;
        }
        form.append("telephone", client_telephone);


        var client_siret = ""
        if (document.getElementsByName("client_siret")) {
            client_siret = document.getElementsByName("client_siret")[0].value;
        }
        form.append("siret", client_siret);

        var client_tva = ""
        if (document.getElementsByName("client_tva")) {
            client_tva = document.getElementsByName("client_tva")[0].value;
        }
        form.append("tva", client_tva);

        var client_website = ""
        if (document.getElementsByName("client_website")) {
            client_website = document.getElementsByName("client_website")[0].value;
        }
        form.append("website", client_website);


        var myurl = process.env.REACT_APP_API_URL + "myclass/api/Add_Partner_Client/";

        axios.post(myurl, form).then(res => {
            if (String(res.data.status) === String("true")) {
                console.log(" In Add_New_PartnerClient  res.data.status = " + res.data.status);
                console.log(" In Add_New_PartnerClient  res.data.message  = " + res.data.message);
                setAdd_New_PartnerClient_api("true");
                setAdd_New_PartnerClient_result(res.data.message);
                setformedit_mode("0");
                setdatamodification("0");
                Disable_fields();
                alert(res.data.message);
                props.Get_List_Partner_Clients();
                props.close_detail_client();


            }
            else if (String(res.data.status) === String("Err_Connexion")) {
                alert('Erreur: ' + res.data.message);
                history.push("/Connexion");
                return;
            }
            else {

                setAdd_New_PartnerClient_api("false");
                setAdd_New_PartnerClient_message(res.data.message);
                alert(res.data.message);

            }


        }).catch((error) => {
            console.warn('Not good man :( Add_New_PartnerClient = ', error);
            setAdd_New_PartnerClient_result("false");
            setAdd_New_PartnerClient_message(" Impossible de recuperer les informations du client")
            alert(" Impossible de recuperer les informations du client");

        })
    }

    const [recordPartnerClient_api, setrecordPartnerClient_api] = useState("");
    const [recordPartnerClient_result, setrecordPartnerClient_result] = useState("");
    const [recordPartnerClient_message, setrecordPartnerClient_message] = useState("");
    function recordPartnerClient(event) {


        var form = new FormData();

        const stored_cookie = getCookie('tokenmysypart');
        form.append("token", stored_cookie);

        // Recupeation des données à enregister

        var client_email = ""
        if (document.getElementsByName("client_email")) {
            client_email = document.getElementsByName("client_email")[0].value;
        }
        form.append("email", client_email);


        var client_nom = ""
        if (document.getElementsByName("client_nom")) {
            client_nom = document.getElementsByName("client_nom")[0].value;
        }
        form.append("nom", client_nom);

        var client_raison_sociale = ""
        if (document.getElementsByName("client_raison_sociale")) {
            client_raison_sociale = document.getElementsByName("client_raison_sociale")[0].value;
        }
        form.append("raison_sociale", client_raison_sociale);

        var client_adresse = ""
        if (document.getElementsByName("client_adresse")) {
            client_adresse = document.getElementsByName("client_adresse")[0].value;
        }
        form.append("adr_adresse", client_adresse);

        var client_code_postal = ""
        if (document.getElementsByName("client_code_postal")) {
            client_code_postal = document.getElementsByName("client_code_postal")[0].value;
        }
        form.append("adr_code_postal", client_code_postal);

        var client_ville = ""
        if (document.getElementsByName("client_ville")) {
            client_ville = document.getElementsByName("client_ville")[0].value;
        }
        form.append("adr_ville", client_ville);

        var client_pays = ""
        if (document.getElementsByName("client_pays")) {
            client_pays = document.getElementsByName("client_pays")[0].value;
        }
        form.append("adr_pays", client_pays);



        var client_telephone = ""
        if (document.getElementsByName("client_telephone")) {
            client_telephone = document.getElementsByName("client_telephone")[0].value;
        }
        form.append("telephone", client_telephone);


        var client_siret = ""
        if (document.getElementsByName("client_siret")) {
            client_siret = document.getElementsByName("client_siret")[0].value;
        }
        form.append("siret", client_siret);

        var client_tva = ""
        if (document.getElementsByName("client_tva")) {
            client_tva = document.getElementsByName("client_tva")[0].value;
        }
        form.append("tva", client_tva);

        var client_website = ""
        if (document.getElementsByName("client_website")) {
            client_website = document.getElementsByName("client_website")[0].value;
        }
        form.append("website", client_website);


        var myurl = process.env.REACT_APP_API_URL + "myclass/api/Update_Partner_Client/";

        axios.post(myurl, form).then(res => {
            if (String(res.data.status) === String("true")) {
                console.log(" In recordPartnerClient  res.data.status = " + res.data.status);
                console.log(" In recordPartnerClient  res.data.message  = " + res.data.message);
                setrecordPartnerClient_api("true");
                setrecordPartnerClient_result(res.data.message);
                setformedit_mode("0");
                setdatamodification("0");
                Disable_fields();
                alert(res.data.message);


            }
            else if (String(res.data.status) === String("Err_Connexion")) {
                alert('Erreur: ' + res.data.message);
                history.push("/Connexion");
                return;
            }
            else {

                setrecordPartnerClient_api("false");
                setrecordPartnerClient_message(res.data.message);
                alert(res.data.message);

            }


        }).catch((error) => {
            console.warn('Not good man :( recordPartnerClient = ', error);
            setrecordPartnerClient_result("false");
            setrecordPartnerClient_message(" Impossible de recuperer les informations du client")
            alert(" Impossible de recuperer les informations du client");

        })
    }


    // Fonction de mise à jour des données de facturation
    const [recordPartnerClient_Invoice_Data_api, setrecordPartnerClient_Invoice_Data_api] = useState("");
    const [recordPartnerClient_Invoice_Data_result, setrecordPartnerClient_Invoice_Data_result] = useState("");
    const [recordPartnerClient_Invoice_Data_message, setrecordPartnerClient_Invoice_Data_message] = useState("");
    function recordPartnerClient_Invoice_Data(event) {


        var form = new FormData();

        const stored_cookie = getCookie('tokenmysypart');
        form.append("token", stored_cookie);

        // Recupeation des données à enregister
        form.append("email", p_client_email);
        form.append("nom", p_client_nom);

        // Données de facturation 
        var client_invoice_email = ""
        if (document.getElementsByName("client_invoice_email")) {
            client_invoice_email = document.getElementsByName("client_invoice_email")[0].value;
        }
        form.append("invoice_email", client_invoice_email);

        var client_invoice_nom = ""
        if (document.getElementsByName("client_invoice_nom")) {
            client_invoice_nom = document.getElementsByName("client_invoice_nom")[0].value;
        }
        form.append("invoice_nom", client_invoice_nom);

        var client_invoice_siret = ""
        if (document.getElementsByName("client_invoice_siret")) {
            client_invoice_siret = document.getElementsByName("client_invoice_siret")[0].value;
        }
        form.append("invoice_siret", client_invoice_siret);

        var client_invoice_tva = ""
        if (document.getElementsByName("client_invoice_tva")) {
            client_invoice_tva = document.getElementsByName("client_invoice_tva")[0].value;
        }
        form.append("invoice_tva", client_invoice_tva);

        var client_invoice_adresse = ""
        if (document.getElementsByName("client_invoice_adresse")) {
            client_invoice_adresse = document.getElementsByName("client_invoice_adresse")[0].value;
        }
        form.append("invoice_adresse", client_invoice_adresse);

        var client_invoice_ville = ""
        if (document.getElementsByName("client_invoice_ville")) {
            client_invoice_ville = document.getElementsByName("client_invoice_ville")[0].value;
        }
        form.append("invoice_ville", client_invoice_ville);

        var client_invoice_code_postal = ""
        if (document.getElementsByName("client_invoice_email")) {
            client_invoice_code_postal = document.getElementsByName("client_invoice_code_postal")[0].value;
        }
        form.append("invoice_code_postal", client_invoice_code_postal);


        var client_invoice_pays = ""
        if (document.getElementsByName("client_invoice_pays")) {
            client_invoice_pays = document.getElementsByName("client_invoice_pays")[0].value;
        }
        form.append("invoice_pays", client_invoice_pays);



        var myurl = process.env.REACT_APP_API_URL + "myclass/api/Update_Partner_Client/";

        axios.post(myurl, form).then(res => {
            if (String(res.data.status) === String("true")) {
                //console.log(" In recordPartnerClient_Invoice_Data  res.data.status = " + res.data.status);
                //console.log(" In recordPartnerClient_Invoice_Data  res.data.message  = " + res.data.message);
                setrecordPartnerClient_Invoice_Data_api("true");
                setrecordPartnerClient_Invoice_Data_result(res.data.message);
                setformedit_mode_invoice("0");
                setdatamodification_invoice("0");
                alert(" Les données de facturation ont été mises à jour.")
                Disable_invoice_fields();
                alert(res.data.message);


            }
            else if (String(res.data.status) === String("Err_Connexion")) {
                alert('Erreur: ' + res.data.message);
                history.push("/Connexion");
                return;
            }
            else {

                setrecordPartnerClient_Invoice_Data_api("false");
                setrecordPartnerClient_Invoice_Data_message(res.data.message);
                alert(res.data.message);

            }


        }).catch((error) => {
            console.warn('Not good man :( recordPartnerClient_Invoice_Data = ', error);
            setrecordPartnerClient_Invoice_Data_result("false");
            setrecordPartnerClient_Invoice_Data_message(" Impossible de recuperer les informations du client")
            alert(" Impossible de recuperer les informations du client");

        })
    }

    function clear_invoice_fields() {
        if (document.getElementsByName("client_invoice_email")) {
            document.getElementsByName("client_invoice_email")[0].value = "";
        }

        if (document.getElementsByName("client_invoice_nom")) {
            document.getElementsByName("client_invoice_nom")[0].value = "";
        }

        if (document.getElementsByName("client_invoice_siret")) {
            document.getElementsByName("client_invoice_siret")[0].value = "";
        }

        if (document.getElementsByName("client_invoice_tva")) {
            document.getElementsByName("client_invoice_tva")[0].value = "";
        }

        if (document.getElementsByName("client_invoice_adresse")) {
            document.getElementsByName("client_invoice_adresse")[0].value = "";
        }

        if (document.getElementsByName("client_invoice_ville")) {
            document.getElementsByName("client_invoice_ville")[0].value = "";
        }

        if (document.getElementsByName("client_invoice_code_postal")) {
            document.getElementsByName("client_invoice_code_postal")[0].value = "";
        }

        if (document.getElementsByName("client_invoice_pays")) {
            document.getElementsByName("client_invoice_pays")[0].value = "";
        }

    }

    function Disable_invoice_fields() {
        if (document.getElementsByName("client_invoice_email")) {
            document.getElementsByName("client_invoice_email")[0].disabled = true;
            document.getElementsByName("client_invoice_email")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_invoice_nom")) {
            document.getElementsByName("client_invoice_nom")[0].disabled = true;
            document.getElementsByName("client_invoice_nom")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_invoice_siret")) {
            document.getElementsByName("client_invoice_siret")[0].disabled = true;
            document.getElementsByName("client_invoice_siret")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_invoice_tva")) {
            document.getElementsByName("client_invoice_tva")[0].disabled = true;
            document.getElementsByName("client_invoice_tva")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_invoice_adresse")) {
            document.getElementsByName("client_invoice_adresse")[0].disabled = true;
            document.getElementsByName("client_invoice_adresse")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_invoice_ville")) {
            document.getElementsByName("client_invoice_ville")[0].disabled = true;
            document.getElementsByName("client_invoice_ville")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_invoice_code_postal")) {
            document.getElementsByName("client_invoice_code_postal")[0].disabled = true;
            document.getElementsByName("client_invoice_code_postal")[0].style.backgroundColor = "#ECEFF1";
        }

        if (document.getElementsByName("client_invoice_pays")) {
            document.getElementsByName("client_invoice_pays")[0].disabled = true;
            document.getElementsByName("client_invoice_pays")[0].style.backgroundColor = "#ECEFF1";
            console.log("iiiiii");
        }

    }

    function Enable_invoice_fields() {
        if (document.getElementsByName("client_invoice_email")) {
            document.getElementsByName("client_invoice_email")[0].disabled = false;
            document.getElementsByName("client_invoice_email")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_invoice_nom")) {
            document.getElementsByName("client_invoice_nom")[0].disabled = false;
            document.getElementsByName("client_invoice_nom")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_invoice_siret")) {
            document.getElementsByName("client_invoice_siret")[0].disabled = false;
            document.getElementsByName("client_invoice_siret")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_invoice_tva")) {
            document.getElementsByName("client_invoice_tva")[0].disabled = false;
            document.getElementsByName("client_invoice_tva")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_invoice_adresse")) {
            document.getElementsByName("client_invoice_adresse")[0].disabled = false;
            document.getElementsByName("client_invoice_adresse")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_invoice_ville")) {
            document.getElementsByName("client_invoice_ville")[0].disabled = false;
            document.getElementsByName("client_invoice_ville")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_invoice_code_postal")) {
            document.getElementsByName("client_invoice_code_postal")[0].disabled = false;
            document.getElementsByName("client_invoice_code_postal")[0].style.backgroundColor = "#FFFFFF";
        }

        if (document.getElementsByName("client_invoice_pays")) {
            document.getElementsByName("client_invoice_pays")[0].disabled = false;
            document.getElementsByName("client_invoice_pays")[0].style.backgroundColor = "#FFFFFF";
        }
    }

    function close_detail_client() {
        props.close_detail_client();
    }

    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("");

        setcontact_telephone("");
        setp_contact_telephone_mobile("");

        setp_contact_fonction("");
        setp_contact_civilite("");

    }

    function clear_contact_fields() {
        if (document.getElementsByName("contact_email")) {
            document.getElementsByName("contact_email")[0].value = "";
        }

        if (document.getElementsByName("contact_nom")) {
            document.getElementsByName("contact_nom")[0].value = "";
        }

        if (document.getElementsByName("contact_prenom")) {
            document.getElementsByName("contact_prenom")[0].value = "";
        }

        if (document.getElementsByName("contact_siret")) {
            document.getElementsByName("contact_siret")[0].value = "";
        }

        if (document.getElementsByName("contact_tva")) {
            document.getElementsByName("contact_tva")[0].value = "";
        }

        if (document.getElementsByName("contact_adresse")) {
            document.getElementsByName("contact_adresse")[0].value = "";
        }

        if (document.getElementsByName("contact_ville")) {
            document.getElementsByName("contact_ville")[0].value = "";
        }

        if (document.getElementsByName("contact_code_postal")) {
            document.getElementsByName("contact_code_postal")[0].value = "";
        }

        if (document.getElementsByName("contact_pays")) {
            document.getElementsByName("contact_pays")[0].value = "";
        }

        if (document.getElementsByName("contact_telephone")) {
            document.getElementsByName("contact_telephone")[0].value = "";
        }

        if (document.getElementsByName("contact_telephone_mobile")) {
            document.getElementsByName("contact_telephone_mobile")[0].value = "";
        }

    }

    // Fonction de mise à jour des données de facturation
    const [recordPartnerClient_Contact_Data_api, setrecordPartnerClient_Contact_Data_api] = useState("");
    const [recordPartnerClient_Contact_Data_result, setrecordPartnerClient_Contact_Data_result] = useState("");
    const [recordPartnerClient_Contact_Data_message, setrecordPartnerClient_Contact_Data_message] = useState("");
    function recordPartnerClient_Contact_Data(event) {


        var form = new FormData();

        const stored_cookie = getCookie('tokenmysypart');
        form.append("token", stored_cookie);

        // Recupeation des données à enregister

        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 = ""
        if (document.getElementsByName("contact_email")) {
            contact_email = document.getElementsByName("contact_email")[0].value;
        }
        form.append("email", contact_email);

        var contact_nom = ""
        if (document.getElementsByName("contact_nom")) {
            contact_nom = document.getElementsByName("contact_nom")[0].value;
        }
        form.append("nom", contact_nom);

        var contact_prenom = ""
        if (document.getElementsByName("contact_prenom")) {
            contact_prenom = document.getElementsByName("contact_prenom")[0].value;
        }
        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;
        }
        form.append("siret", contact_siret);

        var contact_tva = ""
        if (document.getElementsByName("contact_tva")) {
            contact_tva = document.getElementsByName("contact_tva")[0].value;
        }
        form.append("tva", contact_tva);

        var contact_adresse = ""
        if (document.getElementsByName("contact_adresse")) {
            contact_adresse = document.getElementsByName("contact_adresse")[0].value;
        }
        form.append("adr_adresse", contact_adresse);

        var contact_ville = ""
        if (document.getElementsByName("contact_ville")) {
            contact_ville = document.getElementsByName("contact_ville")[0].value;
        }
        form.append("adr_ville", contact_ville);


        var contact_code_postal = ""
        if (document.getElementsByName("contact_code_postal")) {
            contact_code_postal = document.getElementsByName("contact_code_postal")[0].value;
        }
        form.append("adr_code_postal", contact_code_postal);


        var contact_pays = ""
        if (document.getElementsByName("contact_pays")) {
            contact_pays = document.getElementsByName("contact_pays")[0].value;
        }
        form.append("adr_pays", contact_pays);


        var contact_telephone = ""
        if (document.getElementsByName("contact_telephone")) {
            contact_telephone = document.getElementsByName("contact_telephone")[0].value;
        }
        form.append("telephone", contact_telephone);


        var contact_telephone_mobile = ""
        if (document.getElementsByName("contact_telephone_mobile")) {
            contact_telephone_mobile = document.getElementsByName("contact_telephone_mobile")[0].value;
        }
        form.append("telephone_mobile", contact_telephone_mobile);


        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);
                //console.log(" In recordPartnerClient_Contact_Data  res.data.message  = " + res.data.message);
                setrecordPartnerClient_Contact_Data_api("true");
                setrecordPartnerClient_Contact_Data_result(res.data.message);
                Get_List_Contact_Of_client_Part();

                setaddcontact("0");
                setdatamodification_contact("")
                alert(res.data.message);


            }
            else if (String(res.data.status) === String("Err_Connexion")) {
                alert('Erreur: ' + res.data.message);
                history.push("/Connexion");
                return;
            }
            else {

                setrecordPartnerClient_Contact_Data_api("false");
                setrecordPartnerClient_Contact_Data_message(res.data.message);
                alert(res.data.message);

            }


        }).catch((error) => {
            console.warn('Not good man :( recordPartnerClient_Contact_Data = ', error);
            setrecordPartnerClient_Contact_Data_result("false");
            setrecordPartnerClient_Contact_Data_message(" Impossible d'enregistrer les doonées du contact")
            alert(" Impossible d'enregistrer les doonées du contact");

        })
    }


    const [Display_Part_Client_Contact_api, setDisplay_Part_Client_Contact_api] = useState("");
    const [Display_Part_Client_Contact_result, setDisplay_Part_Client_Contact_result] = useState("");
    const [Display_Part_Client_Contact_message, setDisplay_Part_Client_Contact_message] = useState("");
    function Display_Part_Client_Contact(event) {


        var form = new FormData();

        var contactmail = event.currentTarget.getAttribute('contactmail');

        const stored_cookie = getCookie('tokenmysypart');
        form.append("token", stored_cookie);
        form.append("email", contactmail);

        // Recupeation des données à enregister
        form.append("related_collection", "partner_client");
        form.append("related_collection_owner_email", p_client_email);

        console.log(" ### contactmail = ", contactmail);

        var myurl = process.env.REACT_APP_API_URL + "myclass/api/Get_Given_Contact/";

        axios.post(myurl, form).then(res => {
            if (String(res.data.status) === String("true")) {
                console.log(" In Display_Part_Client_Contact  res.data.status = " + res.data.status);
                console.log(" In Display_Part_Client_Contact  res.data.message  = " + res.data.message);
                setDisplay_Part_Client_Contact_api("true");
                setDisplay_Part_Client_Contact_result(res.data.message);
                Get_List_Contact_Of_client_Part();

                setaddcontact("1");
                var mylocalclient_contact = JSON.parse(res.data.message);


                if (mylocalclient_contact) {

                    // Remplissage des doonées du contact
                    if (mylocalclient_contact.nom)
                        setp_contact_nom(mylocalclient_contact.nom);
                    else
                        setp_contact_nom("");

                    if (mylocalclient_contact.email)
                        setp_contact_email(mylocalclient_contact.email);
                    else
                        setp_contact_email("");

                    if (mylocalclient_contact.prenom)
                        setp_contact_prenom(mylocalclient_contact.prenom);
                    else
                        setp_contact_prenom("");


                    if (mylocalclient_contact.siret)
                        setcontact_siret(mylocalclient_contact.siret);
                    else
                        setcontact_siret("");


                    if (mylocalclient_contact.tva)
                        setcontact_tva(mylocalclient_contact.tva);
                    else
                        setcontact_tva("");


                    if (mylocalclient_contact.adr_adresse)
                        setcontact_adresse(mylocalclient_contact.adr_adresse);
                    else
                        setcontact_adresse("");

                    if (mylocalclient_contact.adr_ville)
                        setcontact_ville(mylocalclient_contact.adr_ville);
                    else
                        setcontact_ville("");

                    if (mylocalclient_contact.adr_code_postal)
                        setcontact_code_postal(mylocalclient_contact.adr_code_postal);
                    else
                        setcontact_code_postal("");

                    if (mylocalclient_contact.adr_pays)
                        setcontact_pays(mylocalclient_contact.adr_pays);
                    else
                        setcontact_pays("");

                    if (mylocalclient_contact.telephone)
                        setcontact_telephone(mylocalclient_contact.telephone);
                    else
                        setcontact_telephone("");

                    if (mylocalclient_contact.telephone_mobile)
                        setp_contact_telephone_mobile(mylocalclient_contact.telephone_mobile);
                    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();

            }
            else if (String(res.data.status) === String("Err_Connexion")) {
                alert('Erreur: ' + res.data.message);
                history.push("/Connexion");
                return;
            }
            else {

                setDisplay_Part_Client_Contact_api("false");
                setDisplay_Part_Client_Contact_message(res.data.message);
                alert(res.data.message);

            }


        }).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 detail du contact")
            alert(" Impossible de recuperer les details du contact");

        })
    }



    return (
        <div className="add_partner_client">

            {String(props.new_customer) === "1" && <div className="div_row">
                <div className="div_row">
                    <Button variant="outlined" onClick={submenu_donnee_client} className="detail_submenu" id='submenu_donnee_client' name='submenu_donnee_client'>Données Client</Button>
                </div>

                <div className="training_caract">
                    <TextField
                        required
                        name="client_email"
                        label="Email"
                        InputLabelProps={{
                            shrink: true,
                        }}
                        disabled={false}
                        className="disabled_style"
                        value={p_client_email}
                        onChange={(e) => setclient_email(e.target.value)}

                    />
                </div>


                <div className="training_caract">
                    <TextField
                        required
                        name="client_nom"
                        label="Nom"
                        InputLabelProps={{
                            shrink: true,
                        }}
                        disabled={false}
                        className="disabled_style"
                        value={p_client_nom}
                        onChange={(e) => setclient_nom(e.target.value)}

                    />
                </div>


                <div className="training_caract">
                    <TextField
                        required
                        name="client_raison_sociale"
                        label="raison_sociale"
                        InputLabelProps={{
                            shrink: true,
                        }}
                        disabled={false}
                        className="disabled_style"
                        value={p_client_raison_sociale}
                        onChange={(e) => setclient_raison_sociale(e.target.value)}
                    />
                </div>


                <div className="training_caract">
                    <TextField
                        required
                        name="client_siret"
                        label="N° Siret"
                        InputLabelProps={{
                            shrink: true,
                        }}
                        disabled={false}
                        className="disabled_style"
                        value={p_client_siret}
                        onChange={(e) => setclient_siret(e.target.value)}
                    />
                </div>

                <div className="training_caract">
                    <TextField
                        required
                        name="client_tva"
                        label="N° TVA"
                        InputLabelProps={{
                            shrink: true,
                        }}
                        disabled={false}
                        className="disabled_style"
                        value={p_client_tva}
                        onChange={(e) => setclient_tva(e.target.value)}
                    />
                </div>

                <div className="training_caract">
                    <TextField
                        required
                        name="client_adresse"
                        label="Adresse"
                        InputLabelProps={{
                            shrink: true,
                        }}
                        disabled={false}
                        className="disabled_style"
                        value={p_client_adresse}
                        onChange={(e) => setclient_adresse(e.target.value)}
                    />
                </div>
                <div className="training_caract">
                    <TextField
                        required
                        name="client_ville"
                        label="ville"
                        InputLabelProps={{
                            shrink: true,
                        }}
                        disabled={false}
                        className="disabled_style"
                        value={p_client_ville}
                        onChange={(e) => setclient_ville(e.target.value)}
                    />
                </div>
                <div className="training_caract">
                    <TextField
                        required
                        name="client_code_postal"
                        label="Code Postal"
                        InputLabelProps={{
                            shrink: true,
                        }}
                        disabled={false}
                        className="disabled_style"
                        value={p_client_code_postal}
                        onChange={(e) => setclient_code_postal(e.target.value)}
                    />
                </div>
                <div className="training_caract">
                    <TextField
                        required
                        name="client_pays"
                        label="Pays"
                        InputLabelProps={{
                            shrink: true,
                        }}
                        disabled={false}
                        className="disabled_style"
                        value={p_client_pays}
                        onChange={(e) => setclient_pays(e.target.value)}
                    />
                </div>

                <div className="training_caract">
                    <TextField
                        required
                        name="client_telephone"
                        label="Telephone"
                        InputLabelProps={{
                            shrink: true,
                        }}
                        disabled={false}
                        className="disabled_style"
                        value={p_client_telephone}
                        onChange={(e) => setclient_telephone(e.target.value)}
                    />
                </div>

                <div className="training_caract">
                    <TextField
                        required
                        name="client_website"
                        label="Site web"
                        InputLabelProps={{
                            shrink: true,
                        }}
                        disabled={false}
                        className="disabled_style"
                        value={p_client_website}
                        onChange={(e) => setclient_website(e.target.value)}
                    />
                </div>


                <div className="div_row" style={{ "border": "None" }}>
                    &nbsp;
                </div>


                <div className="div_row">
                    <div className="div_row_gauche">
                        <Button variant="contained" color="success" className="bton_enreg " onClick={confirm_add_user}>Enregistrer &nbsp; <AiTwotoneSave /> </Button>
                    </div>
                    <div className="div_row_droite" style={{ "textAlign": "right" }}>
                        <Button variant="contained" color="success" className="bton_annule" onClick={close_detail_client}>Fermer</Button>
                    </div> 
                </div>
            </div>
            }

            {String(props.new_customer) !== "1" && <div className="div_row">
                <div className="div_row">
                    <Button variant="outlined" onClick={submenu_donnee_client} className="detail_submenu" id='submenu_donnee_client' name='submenu_donnee_client'>Données Client</Button>
                    <Button variant="outlined" onClick={submenu_donnee_facturation} className="detail_submenu" id='submenu_donnee_facturation' name='submenu_donnee_facturation'>Données Facturation</Button>
                    <Button variant="outlined" onClick={submenu_contact} className="detail_submenu" id='submenu_contact' name='submenu_contact'>Contact & Adresses</Button>
                    <Button variant="outlined" onClick={submenu_activite} className="detail_submenu" id='submenu_activite' name='submenu_activite'>Activité</Button>
                    <Button variant="outlined" onClick={submenu_devis} className="detail_submenu" id='submenu_devis' name='submenu_devis'>Devis</Button>
                    <Button variant="outlined" onClick={submenu_cmd} className="detail_submenu" id='submenu_cmd' name='submenu_cmd'>Commandes</Button>
                    <Button variant="outlined" onClick={submenu_factures} className="detail_submenu" id='submenu_factures' name='submenu_factures'>Factures</Button>
                    <Button variant="outlined" onClick={submenu_stagiaires} className="detail_submenu" id='submenu_stagiaires' name='submenu_stagiaires'>Stagiaires</Button>
                </div>

                {String(submenu).trim() === "submenu_donnee_client" && <div className="training_data" onChange={DataUpdated}>

                    <div className="training_caract">
                        <TextField
                            required
                            name="client_email"
                            label="Email"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_email}
                            onChange={(e) => setclient_email(e.target.value)}

                        />
                    </div>


                    <div className="training_caract">
                        <TextField
                            required
                            name="client_nom"
                            label="Nom"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_nom}
                            onChange={(e) => setclient_nom(e.target.value)}

                        />
                    </div>


                    <div className="training_caract">
                        <TextField
                            required
                            name="client_raison_sociale"
                            label="raison_sociale"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_raison_sociale}
                            onChange={(e) => setclient_raison_sociale(e.target.value)}
                        />
                    </div>


                    <div className="training_caract">
                        <TextField
                            required
                            name="client_siret"
                            label="N° Siret"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_siret}
                            onChange={(e) => setclient_siret(e.target.value)}
                        />
                    </div>

                    <div className="training_caract">
                        <TextField
                            required
                            name="client_tva"
                            label="N° TVA"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_tva}
                            onChange={(e) => setclient_tva(e.target.value)}
                        />
                    </div>

                    <div className="training_caract">
                        <TextField
                            required
                            name="client_adresse"
                            label="Adresse"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_adresse}
                            onChange={(e) => setclient_adresse(e.target.value)}
                        />
                    </div>
                    <div className="training_caract">
                        <TextField
                            required
                            name="client_ville"
                            label="ville"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_ville}
                            onChange={(e) => setclient_ville(e.target.value)}
                        />
                    </div>
                    <div className="training_caract">
                        <TextField
                            required
                            name="client_code_postal"
                            label="Code Postal"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_code_postal}
                            onChange={(e) => setclient_code_postal(e.target.value)}
                        />
                    </div>
                    <div className="training_caract">
                        <TextField
                            required
                            name="client_pays"
                            label="Pays"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_pays}
                            onChange={(e) => setclient_pays(e.target.value)}
                        />
                    </div>

                    <div className="training_caract">
                        <TextField
                            required
                            name="client_telephone"
                            label="Telephone"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_telephone}
                            onChange={(e) => setclient_telephone(e.target.value)}
                        />
                    </div>

                    <div className="training_caract">
                        <TextField
                            required
                            name="client_website"
                            label="Site web"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_website}
                            onChange={(e) => setclient_website(e.target.value)}
                        />
                    </div>


                    <div className="div_row" style={{ "border": "None" }}>
                        &nbsp;
                    </div>

                    {String(datamodification) === "1" && <div className="div_row">
                        <div className="koUpdateData" style={{ "color": "orange", "textAlign": "center" }}> /!\ Pensez à enregistrer les modifications</div></div>}
                    {String(formedit_mode) === "1" && <div className="div_row">
                        <div className="div_row_gauche">
                            <Button variant="contained" color="success" className="bton_enreg " onClick={recordPartnerClient}>Enregistrer &nbsp; <AiTwotoneSave /> </Button>
                        </div>
                        <div className="div_row_droite" style={{ "textAlign": "right" }}>
                            <Button variant="contained" color="success" className="bton_annule" onClick={AnnulerEdit}>Annuler</Button>
                        </div>
                    </div>
                    }


                    {String(formedit_mode) !== "1" && <div className="div_row">

                        <div className="div_row_droite" style={{ "textAlign": "right" }}>
                            <Button variant="contained" color="success" className="bton_edit" onClick={DataEditMode}> Modifier</Button>
                        </div>
                    </div>
                    }

                </div>}

                {String(submenu).trim() === "submenu_donnees_facturation" && <div className="training_data" onChange={DataUpdated_Invoice_Data}>

                    <div className="training_caract">
                        <TextField
                            required
                            name="client_invoice_email"
                            label="Email de Facturation"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_invoice_email}
                            onChange={(e) => setclient_invoice_email(e.target.value)}
                        />
                    </div>


                    <div className="training_caract">
                        <TextField
                            required
                            name="client_invoice_nom"
                            label="Nom de Facturation"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_invoice_nom}
                            onChange={(e) => setclient_invoice_nom(e.target.value)}
                        />
                    </div>



                    <div className="training_caract">
                        <TextField
                            required
                            name="client_invoice_siret"
                            label="N° Siret Facturation"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_invoice_siret}
                            onChange={(e) => setclient_invoice_siret(e.target.value)}
                        />
                    </div>

                    <div className="training_caract">
                        <TextField
                            required
                            name="client_invoice_tva"
                            label="N° TVA Facturation"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_invoice_tva}
                            onChange={(e) => setclient_invoice_tva(e.target.value)}
                        />
                    </div>

                    <div className="training_caract">
                        <TextField
                            required
                            name="client_invoice_adresse"
                            label="Adresse"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_invoice_adresse}
                            onChange={(e) => setclient_invoice_adresse(e.target.value)}
                        />
                    </div>
                    <div className="training_caract">
                        <TextField
                            required
                            name="client_invoice_ville"
                            label="ville"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_invoice_ville}
                            onChange={(e) => setclient_invoice_ville(e.target.value)}
                        />
                    </div>
                    <div className="training_caract">
                        <TextField
                            required
                            name="client_invoice_code_postal"
                            label="Code Postal"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_invoice_code_postal}
                            onChange={(e) => setclient_invoice_code_postal(e.target.value)}
                        />
                    </div>
                    <div className="training_caract">
                        <TextField
                            required
                            name="client_invoice_pays"
                            label="Pays"
                            InputLabelProps={{
                                shrink: true,
                            }}
                            disabled={false}
                            className="disabled_style"
                            value={p_client_invoice_pays}
                            onChange={(e) => setclient_invoice_pays(e.target.value)}
                        />
                    </div>


                    <div className="div_row" style={{ "border": "None" }}>
                        &nbsp;
                    </div>

                    {String(datamodification_invoice) === "1" && <div className="div_row">
                        <div className="koUpdateData" style={{ "color": "orange", "textAlign": "center" }}> /!\ Pensez à enregistrer les modifications</div></div>}
                    {String(formedit_mode_invoice) === "1" && <div className="div_row">
                        <div className="div_row_gauche">
                            <Button variant="contained" color="success" className="bton_enreg " onClick={recordPartnerClient_Invoice_Data}>Enregistrer &nbsp; <AiTwotoneSave /> </Button>
                        </div>
                        <div className="div_row_droite" style={{ "textAlign": "right" }}>
                            <Button variant="contained" color="success" className="bton_annule" onClick={AnnulerEdit_Invoice_Data}>Annuler</Button>
                        </div>
                    </div>
                    }
                    {String(formedit_mode_invoice) !== "1" && <div className="div_row">

                        <div className="div_row_droite" style={{ "textAlign": "right" }}>
                            <Button variant="contained" color="success" className="bton_edit" onClick={DataEditMode_Invoice_Data}> Modifier</Button>
                        </div>
                    </div>
                    }

                </div>}

                {String(submenu).trim() === "submenu_contact" && <div className="training_data">

                    {String(addcontact) !== "1" && <div className="div_row" style={{ "marginLeft": "5px", "marginRight": "5px", "paddingRight": "10px" }}>
                        <div className="div_row" onClick={Add_Contact} > <AiOutlineUserAdd /> Ajouter un contact  </div>
                        <div className="div_row scroll_mysy">
                            <div className="contact_grid">

                                {Get_List_Contact_Of_client_Part_result && String(Get_List_Contact_Of_client_Part_api) === "true" &&
                                    Get_List_Contact_Of_client_Part_result.map((client) => (

                                        <div contactmail={String(JSON.parse(client).email)} onClick={Display_Part_Client_Contact}>
                                            {(JSON.parse(client).nom || JSON.parse(client).prenom) && <nav className="grid_title">  {String(JSON.parse(client).prenom)} &nbsp; {String(JSON.parse(client).nom)} <hr/> </nav>}
                                            {JSON.parse(client).fonction && <nav> {String(JSON.parse(client).fonction)} </nav>}
                                            {JSON.parse(client).email && <nav> {String(JSON.parse(client).email)} </nav>}
                                            {JSON.parse(client).telephone && <nav> {String(JSON.parse(client).telephone)} </nav>}

                                        </div>


                                    ))}
                            </div>
                        </div>
                    </div>}

                    {String(addcontact) === "1" && <div className="div_row" style={{ "marginLeft": "5px", "marginRight": "5px" }} onChange={DataUpdated_Contact_Data}>
                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_email"
                                label="Email"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_email}
                                onChange={(e) => setp_contact_email(e.target.value)}

                            />
                        </div>

                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_civilite"
                                label="Civilité"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_civilite}
                                onChange={(e) => setp_contact_civilite(e.target.value)}

                            />
                        </div>


                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_nom"
                                label="Nom"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_nom}
                                onChange={(e) => setp_contact_nom(e.target.value)}

                            />
                        </div>


                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_prenom"
                                label="Prenom"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_prenom}
                                onChange={(e) => setp_contact_prenom(e.target.value)}
                            />
                        </div>


                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_fonction"
                                label="Fonction"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_fonction}
                                onChange={(e) => setp_contact_fonction(e.target.value)}

                            />
                        </div>


                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_siret"
                                label="N° Siret"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_siret}
                                onChange={(e) => setcontact_siret(e.target.value)}
                            />
                        </div>

                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_tva"
                                label="N° TVA"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_tva}
                                onChange={(e) => setcontact_tva(e.target.value)}
                            />
                        </div>

                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_adresse"
                                label="Adresse"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_adresse}
                                onChange={(e) => setcontact_adresse(e.target.value)}
                            />
                        </div>
                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_ville"
                                label="ville"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_ville}
                                onChange={(e) => setcontact_ville(e.target.value)}
                            />
                        </div>
                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_code_postal"
                                label="Code Postal"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_code_postal}
                                onChange={(e) => setcontact_code_postal(e.target.value)}
                            />
                        </div>
                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_pays"
                                label="Pays"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_pays}
                                onChange={(e) => setcontact_pays(e.target.value)}
                            />
                        </div>

                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_telephone"
                                label="Telephone"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_telephone}
                                onChange={(e) => setcontact_telephone(e.target.value)}
                            />
                        </div>

                        <div className="training_caract">
                            <TextField
                                required
                                name="contact_telephone_mobile"
                                label="Téléphone Mobile"
                                InputLabelProps={{
                                    shrink: true,
                                }}
                                disabled={false}
                                className="disabled_style"
                                value={p_contact_telephone_mobile}
                                onChange={(e) => setp_contact_telephone_mobile(e.target.value)}
                            />
                        </div>

                        <div className="div_row" style={{ "border": "None" }}>
                            &nbsp;
                        </div>


                        {String(datamodification_contact) === "1" && <div className="div_row">
                            <div className="koUpdateData" style={{ "color": "orange", "textAlign": "center" }}> /!\ Pensez à enregistrer les modifications</div></div>}

                        {String(formedit_mode_contact) === "1" && <div className="div_row">
                            <div className="div_row_gauche">
                                <Button variant="contained" color="success" className="bton_enreg " onClick={recordPartnerClient_Contact_Data}>Enregistrer &nbsp; <AiTwotoneSave /> </Button>
                            </div>
                            <div className="div_row_droite" style={{ "textAlign": "right" }}>
                                <Button variant="contained" color="success" className="bton_annule" onClick={Close_Contact}>Annuler</Button>
                            </div>
                        </div>
                        }
                        {String(formedit_mode_contact) !== "1" && <div className="div_row">

                            <div className="div_row_gauche">
                                <Button variant="contained" color="success" className="bton_enreg " onClick={retour_liste_contact}>Liste Contacts &nbsp; <GrOrderedList /> </Button>
                            </div>

                            <div className="div_row_droite" style={{ "textAlign": "right" }}>
                                <Button variant="contained" color="success" className="bton_edit" onClick={DataEditMode_Contact_Data}> Modifier</Button>
                            </div>
                        </div>
                        }

                    </div>}

                </div>}


                {String(submenu).trim() === "submenu_activite" && <div className="training_data">
                    < PartnerClientActivite email={p_client_email} />
                </div>}


                <div className="div_row" style={{
                    "border": "None", "marginLeft": "auto", "marginLeft": "auto", "marginRight": "auto", "textAlign": "center",
                    "marginTop": "1rem", "cursor": "pointer", "marginBottom": "1rem", "marginLeft": "auto", "marginRight": "auto"
                }} onClick={close_detail_client}>
                    <IoCloseCircleOutline /> &nbsp; Fermer
                </div>
            </div>}
        </div>
    );
}

export default AddParnerClient;

