<?php

global $aModel;
global $Route;
global $Session;

$fkUser = $Session->_user["rowid"];
$fkRole = $Session->_user["fk_role"];

$metacss = '<link href="/pub/res/css/schat.css" rel="stylesheet" type="text/css"/>';
$barre = "";
ob_start();
?>
  <div id="verticalBar">
    <div id="verticalBarContent">
      <div id="vb-buttons" class="mb-1">
        <button class="btn btn-default" id="btnDevisArchives" title="Voir les devis archivés"><i class="fa fa-stack-overflow fa-lg"></i> Devis archivés</button>
        <button class="btn btn-success" id="btnCreateDevis" title="Créer un nouveau devis"><i class="fa fa-plus fa-lg"></i> Créer un devis</button>
        <div class="row">
          <div class="col-md-9">
            <div class="input-group mt-1">
              <input type="text" class="form-control" id="searchDevis" placeholder="Rechercher un devis par le nom du client, du contact, ville, opportunité..." maxlength="30">
              <span class="input-group-addon">
                <i class="fa fa-times clickable" id="btnResetSearch" style="display:none;"></i>
              </span>
            </div>
          </div>
        </div>
      </div>
      <?php
      if ($aModel["last_devis"] > 0) {
        echo '<div class="pan bg-warning">';
        echo '<div class="pan-heading"><div class="pan-title">Mon dernier devis créé ou modifié</div></div>';
        echo '<div class="pan-body">';
        foreach ($aModel["devis"] as $devis) {
          if ($devis["rowid"] == $aModel["last_devis"]) {
            echo '<table class="table table-responsive table-bordered table-fixed mb-0"><tbody><tr id="tr_lastDevis_' . $devis["rowid"] . '">';
            echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">#' . $devis["rowid"] . '</td>';
            $dateDem = substr($devis["date_demande"], 8, 2) . '/' . substr($devis["date_demande"], 5, 2) . ' ' . substr($devis["date_demande"], 0, 4);
            if ($devis["chk_speciaux"] == 1) {
              $cellDateDem = '<span data-after-text="S" data-after-type="blue circle">' . $dateDem . '</span>';
            } else {
              $cellDateDem = $dateDem;
            }
            echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $cellDateDem . '</td>';
            $dateRem = substr($devis["date_remise"], 8, 2) . '/' . substr($devis["date_remise"], 5, 2) . ' ' . substr($devis["date_remise"], 0, 4);
            echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $dateRem . '</td>';
            echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $devis["num_opportunite"] . '</td>';
            if ($devis["fk_client"] == 0) {
              $ville = $devis["ville_new_client"];
              $libelle = '<span data-after-text="N" data-after-type="red circle">' . $devis["lib_new_client"] . '</span>';

            } else {
              $ville = $devis["ville"];
              $libelle = $devis["libelle"];
            }
            echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $ville . '</td>';
            echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $libelle . '</td>';
            echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $devis["lib_marche"] . '</td>';
            $montant = floatval($devis["montant_total_ht_remise"]);
            echo '<td class="clickable celDevis right" data-rid="' . $devis["rowid"] . '">' . number_format($montant, 2, ',', ' ') . ' &euro;</td>';
            $margeTotale = floatval($devis["marge_totale"]);
            echo '<td class="clickable celDevis right" data-rid="' . $devis["rowid"] . '">' . number_format($margeTotale, 2, ',', ' ') . ' &percnt;</td>';
            echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $devis["lib_statut"] . '</td>';
            echo '</tr></tbody></table>';
            break;
          }
        }
        echo '</div>';
        echo '</div>';
      }
      ?>
      <div class="row">
        <div class="col-md-9">
          <div id="vb-dossiers-statuts" class="mt-1">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <?php
              $i = 0;
              foreach ($aModel["statuts_devis"] as $dossier) {
                $active = ($i == 0) ? "active" : "";
                $lib = $dossier["libelle"];
                $badge = "";
                if (isset($aModel["nb_devis"][$dossier["rowid"]])) {
                  $badge = 'data-after-text="' . $aModel["nb_devis"][$dossier["rowid"]] . '" data-after-type="orange badge top left"';
                }
                echo '<li role="presentation" class="' . $active . '" id="liStat' . $i . '"' . $badge . '><a href="#dos' . $i . '" aria-controls="dos' . $i . '" role="tab" data-toggle="tab">' . $lib . '</a></li>';
                $i++;
              }
              ?>
            </ul>
            <div class="tab-content">
              <?php
              $iDos = 0;
              foreach ($aModel["statuts_devis"] as $dossier) {
                $active = ($iDos == 0) ? "active" : "";
                echo '<div role="tabpanel" class="tab-pane p-0 ' . $active . '" id="dos' . $iDos . '">';
                echo '<div class="border cm-scrollbar cm-table-w-scroll table-responsive table-800">';
                echo '<table class="table table-responsive table-bordered table-fixed" id="tblDos' . $iDos . '">';
                echo '<thead><tr>';
                echo '<th class="header clickable" scope="col" width="5%" data-sortable="true" data-sort-type="number" data-column-index="0">#</th>';
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="date" data-column-index="1">Demande</th>';
                $colIndex = 2;
                if (($fkRole == 2 && $iDos == 2) || ($fkRole == 1 && $iDos == 1)) {
                  // C'est un DV et sur le dossier Encours de validation DV
                  // Ou le Dir-CO sur le dossier de validation DIR-CO
                  // on affiche la colonne du nom du RR pour qu'il puisse savoir qui a fait la demande
                  echo '<th class="header clickable" scope="col" width="15%" data-sortable="true" data-sort-type="text" data-column-index="' . $colIndex . '">RR</th>';
                  $colIndex++;
                }
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="' . $colIndex . '">Opport.</th>';
                echo '<th class="header clickable" scope="col" width="5%" data-sortable="true" data-sort-type="number" data-column-index="' . ($colIndex + 1) . '">CP</th>';
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="' . ($colIndex + 2) . '">Ville</th>';
                echo '<th class="header clickable" scope="col" width="15%" data-sortable="true" data-sort-type="text" data-column-index="' . ($colIndex + 3) . '">Client</th>';
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="' . ($colIndex + 4) . '">Marché</th>';
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="number" data-column-index="' . ($colIndex + 5) . '">Total HT</th>';
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="number" data-column-index="' . ($colIndex + 6) . '">Marge Totale</th>';
                echo '<th class="header" scope="col" width="12%"></th>';
                echo '</tr></thead>';
                echo '<tbody id="tblBodyDos' . $iDos . '">';
                $idStatut = $dossier["rowid"];
                $i = 0;
                foreach ($aModel["devis"] as $devis) {
                  if ($devis["fk_statut_devis"] == $idStatut) {

                    $refuse = false;
                    $trClass = '';
                    if ($idStatut > 1 && $idStatut < 4) {
                      if ($devis["chk_validat"] == 0 && $devis["fk_user_validat"] > 0) {
                        $trClass = 'class="bg-warning" title="Devis refusé"';
                        $refuse = true;
                      }
                    }
                    echo '<tr id="tr_' . $devis["rowid"] . '" ' . $trClass . '>';

                    echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $devis["rowid"] . '</td>';
                    $dateDem = substr($devis["date_demande"], 8, 2) . '/' . substr($devis["date_demande"], 5, 2) . '/' . substr($devis["date_demande"], 0, 4);
                    if ($devis["chk_speciaux"] == 1) {
                      $cellDateDem = '<span data-after-text="S" data-after-type="blue circle">' . $dateDem . '</span>';
                    } else {
                      $cellDateDem = $dateDem;
                    }
                    echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $cellDateDem . '</td>';
                    if (($fkRole == 2 && $iDos == 2) || ($fkRole == 1 && $iDos == 1)) {
                      // C'est un DV et sur le dossier Encours de validation DV
                      // Ou le Dir-CO sur le dossier de validation DIR-CO
                      // on affiche la colonne du nom du RR pour qu'il puisse savoir qui a fait la demande
                      echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $devis["prenom"] . '. ' . $devis["nom"] . '</td>';
                    }
                    echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $devis["num_opportunite"] . '</td>';

                    if ($devis["fk_client"] == 0) {
                      $cp = substr($devis["cp_new_client"], 0, 2);
                      $ville = $devis["ville_new_client"];
                      $libelle = '<span data-after-text="N" data-after-type="red circle">' . $devis["lib_new_client"] . '</span>';
                    } else {
                      $cp = substr($devis["cp"], 0, 2);
                      $ville = $devis["ville"];
                      $libelle = $devis["libelle"];
                    }
                    echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $cp . '</td>';
                    echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $ville . '</td>';
                    echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $libelle . '</td>';
                    echo '<td class="clickable celDevis" data-rid="' . $devis["rowid"] . '">' . $devis["lib_marche"] . '</td>';
                    $montant = floatval($devis["montant_total_ht_remise"]);
                    echo '<td class="clickable celDevis right" data-rid="' . $devis["rowid"] . '">' . number_format($montant, 2, ',', ' ') . ' &euro;</td>';
                    $margeTotale = floatval($devis["marge_totale"]);
                    echo '<td class="clickable celDevis right" data-rid="' . $devis["rowid"] . '">' . number_format($margeTotale, 2, ',', ' ') . ' &percnt;</td>';
                    echo '<td class="center">';
                    echo '<div class="btn-group">';
                    if ($devis["fk_statut_devis"] == 1 || $refuse) {
                      echo '<button class="btn btn-danger btn-xs btnSupprDevis" data-rid="' . $devis["rowid"] . '" title="Supprimer ce devis"><i class="fa fa-trash-o"></i></button>';
                    }
                    echo '<button class="btn btn-primary btn-xs btnExpExcelDevis" data-rid="' . $devis["rowid"] . '" title="Exporter ce devis au format Excel"><i class="fa fa-file-excel-o"></i></button>';
                    echo '<button class="btn btn-info btn-xs btnDupDevis" data-rid="' . $devis["rowid"] . '" title="Dupliquer ce devis"><i class="fa fa-copy"></i></button>';
                    if ($devis["fk_statut_devis"] == 6) {
                      echo '<button class="btn btn-success btn-xs btnValDevis" data-rid="' . $devis["rowid"] . '" title="Valider le devis SAP"><i class="fa fa-check"></i></button>';
                    }
                    echo '</div>';
                    echo '</td></tr>';
                    $i++;
                  }
                }
                if ($i == 0) echo '<tr><td colspan="7" class="center">Aucun devis trouvé pour ce statut</td></tr>';
                echo '</tbody>';
                echo '</table>';
                echo '</div>';
                echo '</div>';
                $iDos++;
              }
              ?>
            </div>
          </div>

          <div id="vb-dossiers-archives" class="mt-1">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <?php
              $i = 0;
              foreach ($aModel["dossiers"] as $dossier) {
                // si $i est un multiple de 15, on crée une nouvelle ligne
                if ($i % 15 == 0 && $i > 0) {
                  echo '<div class="spacer"></div>';
                }
                $active = ($i == 0) ? "active" : "";
                echo '<li role="presentation" class="' . $active . '"><a href="#dosArch' . $i . '" aria-controls="dosArch' . $i . '" role="tab" data-toggle="tab">' . $dossier["dossier"] . '</a></li>';
                $i++;
              }
              ?>
            </ul>
            <div class="tab-content">
              <?php
              $iDos = 0;
              foreach ($aModel["dossiers"] as $dossier) {
                $active = ($iDos == 0) ? "active" : "";
                echo '<div role="tabpanel" class="tab-pane p-0 ' . $active . '" id="dosArch' . $iDos . '">';
                echo '<div class="border cm-scrollbar cm-table-w-scroll table-responsive table-800">';
                echo '<table class="table table-responsive table-bordered table-fixed" id="tblDosArch' . $iDos . '">';
                echo '<thead><tr>';
                echo '<th class="header clickable" scope="col" width="5%" data-sortable="true" data-sort-type="number" data-column-index="0">#</th>';
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="date" data-column-index="1">Demande</th>';
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="2">Opport.</th>';
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="3">Ville</th>';
                echo '<th class="header clickable" scope="col" width="20%" data-sortable="true" data-sort-type="text" data-column-index="4">Client</th>';
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="5">Marché</th>';
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="number" data-column-index="6">Total HT</th>';
                echo '<th class="header clickable" scope="col" width="10%" data-sortable="true" data-sort-type="number" data-column-index="7">Marge Totale</th>';
                echo '<th class="header" scope="col" width="10%"></th>';
                echo '</tr></thead>';
                echo '<tbody id="tblBodyDosArch' . $iDos . '">';
                $libDossier = $dossier["dossier"];
                $i = 0;
                foreach ($aModel["devis"] as $devis) {
                  if ($devis["fk_statut_devis"] != 20) continue;
                  if ($devis["dossier"] != $libDossier) continue;
                  echo '<tr id="trArch_' . $devis["rowid"] . '">';

                  echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $devis["rowid"] . '</td>';

                  $dateDem = substr($devis["date_demande"], 8, 2) . '/' . substr($devis["date_demande"], 5, 2) . ' ' . substr($devis["date_demande"], 0, 4);
                  if ($devis["chk_speciaux"] == 1) {
                    $cellDateDem = '<span data-after-text="S" data-after-type="blue circle">' . $dateDem . '</span>';
                  } else {
                    $cellDateDem = $dateDem;
                  }
                  echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $cellDateDem . '</td>';
                  echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $devis["num_opportunite"] . '</td>';
                  if ($devis["fk_client"] == 0) {
                    $ville = $devis["ville_new_client"];
                    $libelle = '<span data-after-text="N" data-after-type="red circle">' . $devis["lib_new_client"] . '</span>';

                  } else {
                    $ville = $devis["ville"];
                    $libelle = $devis["libelle"];
                  }
                  echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $ville . '</td>';
                  echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $libelle . '</td>';
                  echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $devis["lib_marche"] . '</td>';
                  $montant = floatval($devis["montant_total_ht_remise"]);
                  echo '<td class="clickable celArchives right" data-rid="' . $devis["rowid"] . '">' . number_format($montant, 2, ',', ' ') . ' &euro;</td>';
                  $margeTotale = floatval($devis["marge_totale"]);
                  echo '<td class="clickable celArchives right" data-rid="' . $devis["rowid"] . '">' . number_format($margeTotale, 2, ',', ' ') . ' &percnt;</td>';
                  echo '<td class="center">';
                  echo '<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 2px;">';
                  echo '<button class="btn btn-info btn-xs btnDupDevis" data-rid="' . $devis["rowid"] . '" title="Dupliquer ce devis"><i class="fa fa-copy"></i></button>';
                  echo '<button class="btn btn-primary btn-xs btnExpExcelDevis" data-rid="' . $devis["rowid"] . '" title="Exporter ce devis au format Excel"><i class="fa fa-file-excel-o"></i></button>';
                  echo '<button class="btn btn-warning btn-xs btnPdfDevis" data-rid="' . $devis["rowid"] . '" title="Consulter le devis SAP PDF"><i class="fa fa-file-pdf-o"></i></button>';
                  echo '<button class="btn btn-success btn-xs btnReactiverDevis" data-rid="' . $devis["rowid"] . '" title="Réactiver ce devis"><i class="fa fa-refresh"></i></button>';
                  echo '</div>';
                  echo '</td></tr>';
                  $i++;
                }
                if ($i == 0) echo '<tr><td colspan="7" class="center">Aucun devis archivé trouvé sur ce département</td></tr>';
                echo '</tbody>';
                echo '</table>';
                echo '</div>';
                echo '</div>';
                $iDos++;
              }
              ?>
            </div>
          </div>
        </div>

        <div class="col-md-3">
          <div id="chat-container">
            <div class="chat-bubbles" id="chat-bubbles">
            </div>
            <div class="message-input" id="chat-message-input">
              <div class="input-group">
                <input type="text" class="form-control" placeholder="Ecrire mon message ici..." id="chatInputMessage"/>
                <div class="input-group-addon">
                  <svg class="start-icon clickable" id="chatBtnSend">
                    <use xlink:href="/pub/res/css/images/icons.svg#paperplane"></use>
                  </svg>
                </div>
              </div>

            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="row">
    <div class="col-md-12">
      <div id="divDevis">
        <ul class="nav nav-tabs nav-justified" role="tablist">
          <li role="presentation" class="active"><a href="#tabentete" aria-controls="tabentete" role="tab" data-toggle="tab">1. Identité de l'établissement</a></li>
          <li role="presentation"><a href="#tabproduits" aria-controls="tabproduits" role="tab" data-toggle="tab">2. Sélection Produits</a></li>
          <li role="presentation"><a href="#tabdevis" aria-controls="tabdevis" role="tab" data-toggle="tab">3. Devis</a></li>
        </ul>

        <!-- Tab panes -->
        <div class="tab-content">
          <div role="tabpanel" class="tab-pane active" id="tabentete">
            <div class="container-fluid">
              <form id="frmDevisEntete" autocomplete="off" role="form" method="POST">
                <input type="hidden" id="inp_rowid" name="rowid" value="0"/>
                <input type="hidden" id="inp_fk_client" name="fk_client" value="0"/>
                <input type="hidden" id="inp_type_client" name="type_client" value="0"/>
                <input type="hidden" id="inp_fk_user" name="fk_user" value="0"/>

                <div class="form-group">
                  <label class="control-label col-md-2" for="inp_num_opportunite">N° opportunité :</label>
                  <div class="col-md-2">
                    <input type="text" class="form-control" id="inp_num_opportunite" name="num_opportunite" maxlength="8" required="required"/>
                  </div>
                </div>
                <div class="form-group">
                  <label class="control-label col-md-2" for="inp_date_demande">Date demande :</label>
                  <div class="col-md-2">
                    <input type="date" class="form-control" id="inp_date_demande" name="date_demande" size="10" maxlength="10" placeholder="jj/mm/aaaa" required="required"/>
                  </div>
                  <label class="control-label col-md-2" for="inp_date_remise">A remettre au client le :</label>
                  <div class="col-md-2">
                    <input type="date" class="form-control" id="inp_date_remise" name="date_remise" size="10" maxlength="10" placeholder="jj/mm/aaaa" required="required"/>
                  </div>
                </div>
                <div class="form-group">
                  <label class="control-label col-md-2">Recherche du client :</label>
                  <div class="col-md-3">
                    <input type="checkbox" name="chk_clients_secteur" id="inp_chk_clients_secteur" checked> Sur mon secteur uniquement
                  </div>
                </div>
                <div class="form-group">
                  <label class="control-label col-md-2">Nom du client :</label>
                  <div class="col-md-3">
                    <input type="text" class="form-control" id="inp_lib_client" name="lib_client" required="required" placeholder="Saisir les premiers caractères de son nom..."/>
                  </div>
                  <label class="control-label col-md-2" for="selTypeEtab">Type de l'établissement :</label>
                  <div class="col-md-2">
                    <select class="form-control" id="selTypeEtab" name="selTypeEtab" disabled>
                      <option value="">-</option>
                      <option value="PUB">PUB</option>
                      <option value="PRA">PRA</option>
                      <option value="PRC">PRC</option>
                      <option value="PRD">PRD</option>
                    </select>
                  </div>
                  <div class="col-md-2">
                    <button type="button" class="btn btn-primary" id="btnCreateClient">Nouveau client</button>
                  </div>
                </div>
                <div class="form-group">
                  <label class="control-label col-md-2" for="inp_adresse1">Adresse :</label>
                  <div class="col-md-3">
                    <input type="text" class="form-control" id="inp_adresse1" name="adresse1" readonly="readonly"/>
                  </div>
                  <label class="control-label col-md-2" for="inp_cp">CP :</label>
                  <div class="col-md-2">
                    <input type="text" class="form-control" id="inp_cp" name="cp" readonly="readonly"/>
                  </div>
                </div>
                <div class="form-group">
                  <label class="control-label col-md-2" for="inp_adresse2"></label>
                  <div class="col-md-3">
                    <input type="text" class="form-control" id="inp_adresse2" name="adresse2" placeholder="adresse ligne 2" readonly="readonly"/>
                  </div>
                  <label class="control-label col-md-2" for="inp_ville">Ville :</label>
                  <div class="col-md-3">
                    <input type="text" class="form-control" id="inp_ville" name="ville" readonly="readonly"/>
                  </div>
                </div>
                <div class="form-group">
                  <label class="control-label col-md-2" for="inp_adresse3"></label>
                  <div class="col-md-3">
                    <input type="text" class="form-control" id="inp_adresse3" name="adresse3" placeholder="adresse ligne 3" readonly="readonly"/>
                  </div>
                </div>
                <div class="form-group">
                  <label class="control-label col-md-2" for="sel_contact">Contact :</label>
                  <div class="col-md-4">
                    <select class="form-control" id="sel_contact" name="fk_contact" required="required">
                      <option value="0">- Sélectionner un contact -</option>
                    </select>
                  </div>
                  <div class="col-md-3">
                    <button type="button" class="btn btn-primary" id="btnGererContacts" disabled>Gérer les contacts</button>
                  </div>
                </div>
                <div id="divContactInfos" style="display: none;">
                  <div class="form-group">
                    <label class="control-label col-md-2"></label>
                    <div class="col-md-8">
                      <div class="well well-sm">
                        <div class="row">
                          <div class="col-md-6">
                            <p class="mb-0"><strong>Nom et Prénom :</strong> <span id="info_contact_nom_prenom"></span></p>
                            <p class="mb-0"><strong>Fonction :</strong> <span id="info_contact_fonction"></span></p>
                            <p class="mb-0"><strong>Email :</strong> <span id="info_contact_email"></span></p>
                          </div>
                          <div class="col-md-6">
                            <p class="mb-0"><strong>Téléphone :</strong> <span id="info_contact_telephone"></span></p>
                            <p class="mb-0"><strong>Mobile :</strong> <span id="info_contact_mobile"></span></p>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <label for="fk_marche" class="control-label col-md-2">Marché :</label>
                  <div class="col-md-3">
                    <select class="form-control" name="fk_marche" id="inp_fk_marche" required="required">
                      <option value="0">Aucun</option>
                      <?php
                      foreach ($aModel["marches"] as $marche) {
                        echo '<option value="' . $marche["rowid"] . '">' . $marche["libelle"] . '</option>';
                      }
                      ?>
                    </select>
                  </div>

                  <label for="inp_chk_devis_photos" class="control-label col-md-2">Devis avec photos :</label>
                  <div class="col-md-1">
                    <input type="checkbox" name="chk_devis_photos" id="inp_chk_devis_photos">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inp_commentaire" class="control-label col-md-2">Commentaire :</label>
                  <div class="col-md-8">
                    <input type="text" class="form-control" name="commentaire" id="inp_commentaire"/>
                  </div>
                </div>
              </form>
              <div class="row">
                <div class="col-md-12">
                  <button class="btn btn-success pull-right" id="btnSaveEnTete">Enregistrer l'en-tête de ce devis</button>
                </div>
              </div>
            </div>
          </div>

          <div role="tabpanel" class="tab-pane" id="tabproduits">
            <div class="container-fluid">
              <div class="row">
                <div class="col-md-7">
                  <h4>Liste des produits disponibles</h4>
                  <div id="divProduitsDisponibles">
                    <ul class="nav nav-tabs nav-justified" role="tablist" id="listOngletsProduits">
                      <?php
                      // on crée autant d'onglets que de familles de produits
                      $iTab = 0;
                      foreach ($aModel["familles"] as $famille) {
                        // si $iTab est un multiple de 5, on crée une nouvelle ligne
                        // if ($iTab % 5 == 0 && $iTab > 0) {
                        // echo '<div class="spacer"></div>';
                        // }
                        echo '<li role="presentation"';
                        if ($iTab == 0) {
                          echo ' class="active"';
                        }
                        $libFamille = $famille["libelle"];
                        $libIdFamille = str_replace(" ", "_", $famille["libelle"]);
                        echo '><a href="#tab' . $libIdFamille . '" id="onglet_' . $famille["ordre"] . "_" . $libIdFamille . '" data-famille="' . $libIdFamille . '" data-ordre="' . $famille["ordre"] . '" aria-controls="tab' . $libIdFamille . '" role="tab" data-toggle="tab">' . $libFamille . '</a></li>';
                        $iTab++;
                      }
                      ?>
                    </ul>

                    <!-- Tab panes -->
                    <div class="tab-content">
                      <?php
                      // on crée autant de panneaux que de familles de produits
                      $iTab = 0;
                      foreach ($aModel["familles"] as $famille) {
                        echo '<div role="tabpanel" class="tab-pane';
                        if ($iTab == 0) {
                          echo ' active';
                        }
                        $libIdFamille = str_replace(" ", "_", $famille["libelle"]);
                        echo '" id="tab' . $libIdFamille . '">';
                        // echo '<form class="form-inline">';
                        echo '<div class="form-group">';
                        echo '<label for="inpSearchProduct_' . $libIdFamille . '">Recherche de produits dans cette famille : </label>';
                        echo '<div class="input-group"><input type="text" class="form-control" id="inpSearchProduct_' . $libIdFamille . '" data-idfamille="' . $famille["rowid"] . '" placeholder="code ou libellé" size="50px" />';
                        echo '<div class="input-group-addon"><svg width="18px" height="18px" viewBox="0 0 20 20" role="img" xmlns="http://www.w3.org/2000/svg" aria-labelledby="returnIconTitle" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none" color="#000000"><path d="M19,8 L19,11 C19,12.1045695 18.1045695,13 17,13 L6,13"/> <polyline points="8 16 5 13 8 10"/> </svg></div>';
                        echo '</div></div>';
                        // echo '</form>';
                        echo '<div class="border cm-scrollbar cm-table-w-scroll table-responsive mt-1 table-400">';
                        echo '<table class="table table-striped table-bordered table-responsive table-fixed" id="tblProduits_' . $libIdFamille . '">';
                        echo '<thead>';
                        echo '<tr>';
                        echo '<th class="header" scope="col" width="10%">Sélection</th>';
                        echo '<th class="header" scope="col" width="20%">Code</th>';
                        echo '<th class="header" scope="col" width="30%">Libellé</th>';
                        echo '<th class="header" scope="col" width="10%">Famille</th>';
                        echo '</tr>';
                        echo '</thead>';
                        echo '<tbody>';

                        echo '</tbody>';
                        echo '</table>';
                        echo '</div>';
                        echo '</div>';
                        $iTab++;
                      }
                      ?>
                    </div>
                  </div>
                </div>

                <div class="col-md-5">
                  <h3>Liste des produits sélectionnés pour ce devis</h3>
                  <form class="form" id="frmSelProduits">
                    <input type="hidden" name="fk_devis" id="inp_SelProd_fkDevis"/>
                    <div class="border cm-scrollbar cm-table-w-scroll table-responsive">
                      <table class="table table-bordered table-responsive table-fixed" id="tblProduitsSelect">
                        <thead>
                        <tr>
                          <th class="header" scope="col" width="10%">Retrait</th>
                          <th class="header" scope="col" width="20%">Code</th>
                          <th class="header" scope="col" width="30%">Libellé</th>
                        </tr>
                        </thead>
                        <tbody>

                        </tbody>
                      </table>
                    </div>
                  </form>
                </div>
              </div>
              <div class="row">
                <div class="col-md-12">
                  <button class="btn btn-warning" id="btnSpeciaux"><span data-after-text="S" data-after-type="blue circle">Demande de produits spéciaux</span></button>
                  <button class="btn btn-success pull-right" id="btnSaveSelProduits">Enregistrer les produits sélectionnés</button>
                </div>
              </div>
            </div>  <!-- fin container-fluid -->
          </div>
          <div role="tabpanel" class="tab-pane" id="tabdevis">
            <div class="container-fluid">
              <div class="row">
                <form class="form-inline" id="frmDevis">
                  <input type="hidden" name="inpIdDevis" id="inpIdDevis"/>
                  <div class="col-md-9">
                    <div class="row">
                      <div class="col-md-12">
                        <table class="table mb-0">
                          <tr>
                            <td>
                              <div class="form-group">
                                <label for="inpTotalHT">Total HT avant remise :</label>
                            </td>
                            <td>
                              <div class="input-group">
                                <input type="text" class="form-control numeric" id="inpTotalHT" name="inpTotalHT" readonly="readonly" tabindex="-1" size="12" maxlength="12"/>
                                <div class="input-group-addon">&euro;</div>
                              </div>
                              <?php
                              if ($Conf->_devIp) {
                                echo '<input type="hidden" id="inpCoutTotalAchat" name="inpCoutTotalAchat"/>';
                              }
                              ?>
                            </td>
                            <td></td>
                            <td></td>
                          </tr>
                          <tr>
                            <td>
                              <div class="form-group">
                                <label for="inpTotalRemHT">Total HT après remise :</label>
                            </td>
                            <td>
                              <div class="input-group">
                                <input type="text" class="form-control numeric" id="inpTotalRemHT" name="inpTotalRemHT" readonly="readonly" tabindex="-1" size="12" maxlength="12"/>
                                <div class="input-group-addon">&euro;</div>
                              </div>
                            </td>
                            <td>
                              <div class="form-group">
                                <label for="inpTotalMarge">Marge totale avant logistique :</label>
                            </td>
                            <td>
                              <div class="input-group">
                                <input type="text" class="form-control numeric" id="inpTotalMarge" name="inpTotalMarge" readonly="readonly" tabindex="-1" size="10" maxlength="10"/>
                                <div class="input-group-addon">%</div>
                              </div>
                            </td>
                          </tr>
                          <tr id="trRemisesMarche">
                            <td>
                              <div class="form-group"><label for="">Remises du marché :</label></div>
                            </td>
                            <td colspan="3" id="tdRemisesMarche">
                            </td>
                          </tr>
                        </table>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-12">
                        <div style="overflow-x: auto;">
                          <table class="table table-responsive" width="90%" id="tblDevisPro">
                            <thead>
                            <tr>
                              <th width="10%">Ref</th>
                              <th width="20%">Désignation</th>
                              <th width="10%">Prix vente</th>
                              <th width="10%">Qté</th>
                              <th width="10%">Remise</th>
                              <th width="10%">PU vente remisé</th>
                              <th width="10%">Total HT</th>
                              <th width="10%" class="text-center" title="Variante ou Option">V/O</th>
                              <th width="10%">Marge</th>
                            </tr>
                            </thead>
                            <tbody>
                            </tbody>
                          </table>
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-12">
                        <table id="tblCommentDevis">
                          <tbody class="w-100">
                          <tr>
                            <td width="10%">Commentaire :</td>
                            <td width="90%" colspan="2"><input type="text" class="form-control w-100" id="inpCommentDevis" name="commentDevis"/></td>
                          </tr>
                          <tr>
                            <td width="10%">Demande geste commercial :</td>
                            <td width="90%" colspan="2"><input type="text" class="form-control w-100" id="inpCommentGesteComm" name="commentGesteComm" placeholder="Demande adressée à votre DV"/></td>
                          </tbody>
                        </table>
                      </div>
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="row">
                      <div class="col-md-12">
                        <div class="well" style="background: #b1dfbb">
                          <h5><strong>Latitudes sur la marge avant logistique</strong></h5>
                          <table class="table transparent" style="background: #b1dfbb;">
                            <tr class="transparent">
                              <td class="transparent">Pour le RR</td>
                              <td class="transparent">
                                <div class="input-group"><input type="text" class="form-control numeric" id="inp_latitudeRR" disabled/>
                                  <div class="input-group-addon">%</div>
                                </div>
                              </td>
                            </tr>
                            <tr class="transparent">
                              <td class="transparent">Pour le DV/DGC</td>
                              <td class="transparent">
                                <div class="input-group"><input type="text" class="form-control numeric" id="inp_latitudeDV" disabled/>
                                  <div class="input-group-addon">%</div>
                                </div>
                              </td>
                            </tr>
                            <tr class="transparent">
                              <td class="transparent">Pour le DIR-CO</td>
                              <td class="transparent"><input type="text" class="form-control" id="inp_latitudeAuDela" value="Au-delà" disabled></td>
                            </tr>
                          </table>
                        </div>
                        <div class="well" style="background: #EEE;">
                          <h5 id="titleMarche"><strong>Informations Marché</strong></h5>
                          <table class="table table-bordered table-striped" id="tblMarche">
                            <tr>
                              <td>Tx Remise trimestrielle</td>
                              <td id="tdTxRemiseTrim" class="bold"></td>
                            </tr>
                            <tr>
                              <td>Tx Remise semestrielle</td>
                              <td id="tdTxRemiseSeme" class="bold"></td>
                            </tr>
                            <tr>
                              <td>Tx Remise annuelle</td>
                              <td id="tdTxRemiseAnnu" class="bold"></td>
                            </tr>
                            <tr>
                              <td>Début et fin marché</td>
                              <td id="tdDebutFin" class="bold"></td>
                            </tr>
                            <tr>
                              <td>Date de validité des prix</td>
                              <td id="tdDateValiditePrix" class="bold"></td>
                            </tr>
                            <tr>
                              <td>Garantie</td>
                              <td id="tdGarantie" class="bold"></td>
                            </tr>
                            <tr>
                              <td>Remises commerciales</td>
                              <td id="tdRemisesCo" class="bold"></td>
                            </tr>
                          </table>
                        </div>
                      </div>
                      <div class="row">
                        <div class="col-md-12">

                        </div>
                      </div>
                    </div>
                </form>
              </div>
              <div class="row">
                <div class="col-md-12">
                  <button class="btn btn-primary pull-right" id="btnSaveDevisAndSend" data-statut="2">Demander Traitement SAP</button>
                  <button class="btn btn-success pull-right mr-1" id="btnSaveDevis">Enregistrer ce devis</button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
<?php
$content = ob_get_contents();
ob_clean();

ob_start();
// Endroit destiné aux modales
// Modal pour les produits spéciaux
?>
  <div class="modal draggable fade" id="modalSpeciaux" tabindex="-1" role="dialog" aria-labelledby="modalSpeciauxTitre" data-backdrop="static">
    <div class="modal-dialog modal-xl">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title" id="modSpeciauxTitre"><i class="fa fa-stack-exchange fa-lg"></i> Demande de produits spéciaux</h4>
        </div>
        <div class="modal-body">
          <div class="panel panel-warning">
            <div class="panel-heading ">
              <h3 class="panel-title">
                <span><i class="fa fa-truck"></i> Livraison souhaitée</span>
              </h3>
            </div>
            <div class="panel-body">
              <form class="form-horizontal" id="frmSpeciaux" autocomplete="off" role="form" enctype="multipart/form-data">
                <input type="hidden" id="inp_idDevis_speciaux" name="idDevis_speciaux"/>
                <input type="hidden" id="inp_specialFkProduit_1" name="specialFkProduit_1"/>
                <input type="hidden" id="inp_specialFkProduit_2" name="specialFkProduit_2"/>
                <input type="hidden" id="inp_specialFkProduit_3" name="specialFkProduit_3"/>
                <input type="hidden" id="inp_specialFkProduit_4" name="specialFkProduit_4"/>
                <input type="hidden" id="inp_specialFkProduit_5" name="specialFkProduit_5"/>
                <div class="form-group">
                  <label for="inp_chk_livr_multi" class="control-label col-md-1">Livraisons multiples :</label>
                  <div class="col-md-1">
                    <input type="checkbox" class="form-control" name="chk_livr_multi" id="inp_chk_livr_multi">
                  </div>
                  <label class="control-label col-md-1" for="inp_nb_livr">Si oui, combien :</label>
                  <div class="col-md-1">
                    <input type="number" class="form-control" id="inp_nb_livr" name="nb_livr" size="3" maxlength="3"/>
                  </div>
                  <label class="control-label col-md-1" for="inp_date_livr_1">Date 1ère livraison :</label>
                  <div class="col-md-2">
                    <input type="date" class="form-control" id="inp_date_livr_1" name="date_livr_1" placeholder="jj/mm/aaaa"/>
                  </div>
                  <label for="inp_specialEmail" class="control-label col-md-1">Email Service :</label>
                  <div class="col-md-3">
                    <input type="email" class="form-control" id="inp_specialEmail" name="specialEmail" title="Envoyer un email au service concerné pour cette demande"/>
                  </div>
                </div>
            </div>
          </div>
          <div class="panel panel-primary">
            <div class="panel-heading ">
              <h3 class="panel-title">
                <span id="pnlProduitsSpeciauxTitre"><i class="fa fa-cubes"></i> Produits spéciaux</span>
              </h3>
            </div>
            <div class="panel-body">
              <div class="row">
                <div class="col-md-12">
                  <div style="overflow-x: auto;">
                    <table class="table table-responsive" width="90%" id="tblProduitsSpeciaux">
                      <thead>
                      <tr>
                        <th width="8%">Code</th>
                        <th width="10%">Désignation</th>
                        <th width="5%">Qté</th>
                        <th width="10%">Surcoût<br/>acceptable</th>
                        <th width="5%">Echantillon ?</th>
                        <th width="10%">Quand ?</th>
                        <th width="15%">Concurrent ?</th>
                        <th width="20%">Demande</th>
                      </tr>
                      </thead>
                      <tbody>
                      <?php
                      for ($i = 1; $i <= 5; $i++) {
                        echo '<tr>';
                        echo '<td><input type="text" class="form-control" id="inp_specialCode_' . $i . '" name="specialCode_' . $i . '" placeholder="Code produit"/></td>';
                        echo '<td><input type="text" class="form-control" id="inp_specialLibe_' . $i . '" name="specialLibe_' . $i . '" /></td>';
                        echo '<td><input type="number" step="1" class="form-control" id="inp_specialQte_' . $i . '" name="specialQte_' . $i . '"/></td>';
                        echo '<td><div class="input-group"><input type="text" class="form-control" id="inp_specialCout_' . $i . '" name="specialCout_' . $i . '"/>';
                        echo '<div class="input-group-addon">&euro;</div></div></td>';
                        echo '<td><input type="checkbox" class="form-control" name="chk_specialEchantillon_' . $i . '" id="inp_chk_specialEchantillon_' . $i . '"/></td>';
                        echo '<td><input type="date" class="form-control" id="inp_specialDate_' . $i . '" name="specialDate_' . $i . '"/></td>';
                        echo '<td><input type="text" class="form-control" id="inp_specialConcurrent_' . $i . '" name="specialConcurrent_' . $i . '"/></td>';
                        echo '<td><input type="text" class="form-control" id="inp_specialDescription_' . $i . '" name="specialDescription_' . $i . '"/></td>';
                        echo '</tr>';
                      }
                      ?>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
              </form>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" id="btnCancelSpeciaux" title="Fermer sans enregistrer">Annuler</button>
          <button type="button" class="btn btn-success" id="btnSaveSpeciaux" title="Enregistrer la modification">Enregistrer</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal draggable fade" id="modalCreateClient" tabindex="-1" role="dialog" aria-labelledby="modalCreateClientTitre" data-backdrop="static">
    <div class="modal-dialog modal-xl">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title" id="modCreateClientTitre"><i class="fa fa-user fa-lg"></i> Création d'un nouveau client</h4>
        </div>
        <div class="modal-body">
          <div class="panel panel-primary">
            <div class="panel-heading ">
              <h3 class="panel-title">
                <span><i class="fa fa-user"></i> Saisir ses coordonnées</span>
              </h3>
            </div>
            <div class="panel-body">
              <div class="container-fluid">
                <form class="form-horizontal" id="frmCreateClient" autocomplete="off" role="form" enctype="multipart/form-data">
                  <div class="form-group">
                    <label class="control-label col-md-2" for="inp_create_libelle">Nom de l'établissement :</label>
                    <div class="col-md-4">
                      <input type="text" class="form-control" id="inp_create_libelle" name="create_libelle" maxlength="75"/>
                    </div>
                    <label class="control-label col-md-2" for="inp_create_type_client">Type de l'établissement :</label>
                    <div class="col-md-2">
                      <select class="form-control" name="create_type_client" id="inp_create_type_client">
                        <option value="0">-</option>
                        <?php
                        foreach ($aModel["types_clients"] as $type) {
                          echo '<option value="' . $type["code"] . '">' . $type["code"] . ' - ' . $type["libelle"] . '</option>';
                        }
                        ?>
                      </select>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="control-label col-md-2" for="inp_create_adresse1">Adresse :</label>
                    <div class="col-md-3">
                      <input type="text" class="form-control" id="inp_create_adresse1" name="create_adresse1" maxlength="50"/>
                    </div>
                    <label class="control-label col-md-2" for="inp_create_cp">CP :</label>
                    <div class="col-md-2">
                      <input type="text" class="form-control" id="inp_create_cp" name="create_cp" maxlength="5"/>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="control-label col-md-2" for="inp_create_adresse2"></label>
                    <div class="col-md-3">
                      <input type="text" class="form-control" id="inp_create_adresse2" name="create_adresse2" placeholder="adresse ligne 2" maxlength="50"/>
                    </div>
                    <label class="control-label col-md-2" for="inp_create_ville">Ville :</label>
                    <div class="col-md-3">
                      <input type="text" class="form-control" id="inp_create_ville" name="create_ville" maxlength="50"/>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="control-label col-md-2" for="inp_create_adresse3"></label>
                    <div class="col-md-3">
                      <input type="text" class="form-control" id="inp_create_adresse3" name="create_adresse3" placeholder="adresse ligne 3" maxlength="50"/>
                    </div>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" id="btnCancelCreateClient" title="Fermer sans enregistrer">Annuler</button>
          <button type="button" class="btn btn-success" id="btnSaveCreateClient" title="Enregistrer la modification">Enregistrer</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal draggable fade" id="modalPDFSAP" tabindex="-1" role="dialog" aria-labelledby="modalCreateClientTitre" data-backdrop="static">
    <div class="modal-dialog modal-xl">
      <div class="modal-content">
        <div class="modal-header">
          <form class="form-inline" id="frmValidationRR">
            <input type="text" class="form-control w-75" id="inpCommentPDFSAP" name="commentPDFSAP" placeholder="Saisir un commentaire..." required/>
            <button id="btnValidationRR" class="btn btn-success">Valider</button>
            <button id="btnRefusRR" class="btn btn-danger">Refuser</button>
            <button id="btnCloseRR" class="btn btn-default">Fermer sans répondre</button>
          </form>
          <button id="btnClosePDF" class="btn btn-primary">Fermer le document</button>
        </div>
        <div class="modal-body">
          <div id="pdfContainer">
            <embed src="" frameborder="0" width="100%" height="600px" id="embPdfSAP">
          </div>
        </div>
        <div class="modal-footer">

        </div>
      </div>
    </div>
  </div>

  <div class="modal draggable fade" id="modalCommentProd" tabindex="-1" role="dialog" aria-labelledby="modalCommentProdTitre" data-backdrop="static">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title" id="modCommentProdTitre"> Commentaire sur le produit</h4>
        </div>
        <div class="modal-body">
          <input type="hidden" id="inp_commentProdId" value="0" />
          <div class="form-group">
            <label class="control-label col-md-2" for="inp_commentProd">Commentaire : </label>
            <div class="col-md-8">
              <input type="text" class="form-control w-100" id="inp_commentProd" placeholder="" maxlength="255"/>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" id="btnCancelCommentProd" title="Fermer sans enregistrer">Annuler</button>
          <button type="button" class="btn btn-success" id="btnSaveCommentProd" title="Enregistrer le commentaire">Enregistrer</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal draggable fade" id="modalGererContacts" tabindex="-1" role="dialog" aria-labelledby="modalGererContactsTitre" data-backdrop="static">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title" id="modGererContactsTitre"><i class="fa fa-address-book fa-lg"></i> Gestion des contacts du client</h4>
        </div>
        <div class="modal-body">
          <input type="hidden" id="inp_fk_client_contacts" value="0"/>
          <div class="row mb-2">
            <div class="col-md-12">
              <button type="button" class="btn btn-success btn-sm" id="btnNouveauContact"><i class="fa fa-plus"></i> Nouveau contact</button>
            </div>
          </div>
          <div class="row">
            <div class="col-md-12">
              <div class="table-responsive">
                <table class="table table-bordered table-striped" id="tblContacts">
                  <thead>
                    <tr>
                      <th width="20%">Nom</th>
                      <th width="15%">Prénom</th>
                      <th width="20%">Fonction</th>
                      <th width="15%">Téléphone</th>
                      <th width="20%">Email</th>
                      <th width="10%" class="text-center">Principal</th>
                      <th width="15%" class="text-center">Actions</th>
                    </tr>
                  </thead>
                  <tbody>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" id="btnFermerContacts">Fermer</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal draggable fade" id="modalEditContact" tabindex="-1" role="dialog" aria-labelledby="modalEditContactTitre" data-backdrop="static">
    <div class="modal-dialog modal-md">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title" id="modEditContactTitre"><i class="fa fa-user fa-lg"></i> <span id="modEditContactTitreText">Nouveau contact</span></h4>
        </div>
        <div class="modal-body">
          <form id="frmEditContact" class="form-horizontal" autocomplete="off">
            <input type="hidden" id="inp_contact_rowid" name="rowid" value="0"/>
            <input type="hidden" id="inp_contact_fk_client" name="fk_client" value="0"/>

            <div class="form-group">
              <label class="control-label col-md-3" for="inp_contact_nom_edit">Nom :</label>
              <div class="col-md-8">
                <input type="text" class="form-control" id="inp_contact_nom_edit" name="nom" maxlength="50" required/>
              </div>
            </div>

            <div class="form-group">
              <label class="control-label col-md-3" for="inp_contact_prenom_edit">Prénom :</label>
              <div class="col-md-8">
                <input type="text" class="form-control" id="inp_contact_prenom_edit" name="prenom" maxlength="50" required/>
              </div>
            </div>

            <div class="form-group">
              <label class="control-label col-md-3" for="inp_contact_fonction_edit">Fonction :</label>
              <div class="col-md-8">
                <input type="text" class="form-control" id="inp_contact_fonction_edit" name="fonction" maxlength="50"/>
              </div>
            </div>

            <div class="form-group">
              <label class="control-label col-md-3" for="inp_contact_email_edit">Email :</label>
              <div class="col-md-8">
                <input type="email" class="form-control" id="inp_contact_email_edit" name="email" maxlength="75"/>
              </div>
            </div>

            <div class="form-group">
              <label class="control-label col-md-3" for="inp_contact_telephone_edit">Téléphone :</label>
              <div class="col-md-8">
                <input type="text" class="form-control" id="inp_contact_telephone_edit" name="telephone" maxlength="20"/>
              </div>
            </div>

            <div class="form-group">
              <label class="control-label col-md-3" for="inp_contact_mobile_edit">Mobile :</label>
              <div class="col-md-8">
                <input type="text" class="form-control" id="inp_contact_mobile_edit" name="mobile" maxlength="20"/>
              </div>
            </div>

            <div class="form-group">
              <label class="control-label col-md-3" for="inp_contact_principal_edit">Contact principal :</label>
              <div class="col-md-8">
                <input type="checkbox" id="inp_contact_principal_edit" name="principal" value="1"/>
              </div>
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" id="btnCancelEditContact">Annuler</button>
          <button type="button" class="btn btn-success" id="btnSaveEditContact">Enregistrer</button>
        </div>
      </div>
    </div>
  </div>
<?php
$modal = ob_get_contents();
ob_clean();

ob_start();
echo '<script src="/pub/res/js/jdevis.js"></script>';
echo '<script src="/pub/res/js/jchat.js"></script>';
$jscript = ob_get_contents();
ob_end_clean();

require_once $Route->_layout;
