<?php
global $Route;
global $aModel;
$metacss = '<link href="/pub/res/css/schat.css" rel="stylesheet" type="text/css"/>';
$barre = "";
ob_start();
?>
<style>
.dept-tab a {
  min-width: 50px !important;
  padding: 8px 10px !important;
  font-size: 13px;
}
.table-800 {
  overflow-y: auto !important;
}
#tabArchives .table-800 {
  max-height: 680px !important;
}
.table-800 thead th {
  position: sticky;
  top: 0;
  z-index: 10;
}
</style>
<div class="row" style="margin-bottom: 20px;">
  <div class="col-md-2"></div>
  <div class="col-md-8">
    <div class="input-group">
      <input type="text" class="form-control" id="searchSAP" 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="btnResetSearchSAP" style="display:none;"></i>
      </span>
    </div>
  </div>
  <div class="col-md-2"></div>
</div>
<div id="divSAP" style="margin-top: 20px;">
  <ul class="nav nav-tabs nav-justified" role="tablist">
    <li role="presentation" class="active"><a href="#tabEnCours" aria-controls="tabEnCours" role="tab" data-toggle="tab">Les devis en cours</a></li>
    <li role="presentation"><a href="#tabArchives" aria-controls="tabArchives" role="tab" data-toggle="tab">Les devis archivés</a></li>
  </ul>

  <!-- Tab panes -->
  <div class="tab-content">
    <div role="tabpanel" class="tab-pane active" id="tabEnCours">
      <div class="row">
        <div class="col-md-9">
          <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 text-center clickable" scope="col" width="5%" data-sortable="true" data-sort-type="number" data-column-index="0">#</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="date" data-column-index="1">Date Demande</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="date" data-column-index="2">Date Remise</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="3">Responsable Régional</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="4">Code Etabliss.</th>';
              echo '<th class="header text-center clickable" scope="col" width="15%" data-sortable="true" data-sort-type="text" data-column-index="5">Etablissement</th>';
              echo '<th class="header text-center clickable" scope="col" width="7%" data-sortable="true" data-sort-type="number" data-column-index="6">CP</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="7">Ville</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="8">Marché</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="number" data-column-index="9">Montant Total HT</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="number" data-column-index="10">Marge totale</th>';
              $colIndexActions = 11;
              if ($dossier["rowid"] == 7) {
                // Si le dossier est "A envoyer au client", on affiche la colonne "Email"
                echo '<th class="header text-center" scope="col" width="10%">Email</th>';
                $colIndexActions = 12;
              }
              echo '<th class="header text-center" scope="col" width="20%">Actions <button class="btn btn-info btn-xs btnExportSelectedXML hidden" title="Export XML SAP des devis sélectionnés"><i class="fa fa-scribd fa-lg"></i></button></th>';
              echo '</tr></thead>';
              echo '<tbody id="tblBodyDos' . $iDos . '">';
              $idStatut = $dossier["rowid"];
              $i = 0;
              foreach ($aModel["devisEnCours"] as $devis) {
                if ($devis["fk_statut_devis"] == $dossier["rowid"]) {
                  echo '<tr class="ligEnCours">';
                  if ($devis["chk_maj"] == 1) {
                    $bMaj = 'data-after-text="màj" data-after-type="green pill" title="Devis mis à jour par le RR"';
                  } else {
                    $bMaj = '';
                  }
                  if ($devis["chk_speciaux"] == 1) {
                    $cellId = '<span data-after-text="Sp" data-after-type="blue circle" title="Produits Spéciaux">' . $devis["rowid"] . '</span>';
                  } else {
                    $cellId = '<span>' . $devis["rowid"] . '</span>';
                  }
                  echo '<td class="clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . $cellId . '</td>';
                  echo '<td class="clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . affiche_date($devis["date_demande"]) . '</td>';
                  echo '<td class="clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . affiche_date($devis["date_remise"]) . '</td>';
                  echo '<td class="text-center clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . $devis["prenom"] . ' ' . $devis["nom"] . '</td>';
                  if ($devis["fk_client"] == 0) {
                    echo '<td class="text-center clickable celEnCours" data-rid="' . $devis["rowid"] . '" ><span data-after-text="N" data-after-type="red circle" title="Nouveau client !"> -</span></td>';
                    echo '<td class="clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . $devis["lib_new_client"] . '</td>';
                    echo '<td class="clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . $devis["cp_new_client"] . '</td>';
                    echo '<td class="clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . $devis["ville_new_client"] . '</td>';
                  } else {
                    echo '<td class="text-center clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . $devis["code"] . '</td>';
                    echo '<td class="clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . $devis["libelle"] . '</td>';
                    echo '<td class="clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . $devis["cp"] . '</td>';
                    echo '<td class="clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . $devis["ville"] . '</td>';
                  }
                  echo '<td class="clickable celEnCours" data-rid="' . $devis["rowid"] . '" >' . $devis["lib_marche"] . '</td>';
                  echo '<td class="text-center clickable celEnCours" data-rid="' . $devis["rowid"] . '" ><span ' . $bMaj . '>' . $devis["montant_total_ht_remise"] . ' €</span></td>';
                  $margeTotale = floatval($devis["marge_totale"]);
                  echo '<td class="clickable celEnCours text-center" data-rid="' . $devis["rowid"] . '">' . number_format($margeTotale, 2, ',', ' ') . ' &percnt;</td>';
                  if ($dossier["rowid"] == 7) {
                    if ($devis["email"] == "") {
                      echo '<td class="" ><span data-after-text="!" data-after-type="red circle" title="Pas d\'email !"> -</span></td>';
                    } else {
                      echo '<td class=""><a href="mailto:' . $devis["email"] . '?subject=LINET France - Offre de prix :" title="Envoyer le devis à cette adresse email">' . $devis["email"] . '</a></td>';
                    }
                  }
                  echo '<td class="text-center">';
                  echo '<div class="btn-group">';
                  echo '<button class="btn btn-primary btn-xs btnViewDevisEnCours" title="Consulter le devis" data-rid="' . $devis["rowid"] . '"><i class="fa fa-eye fa-lg"></i></button>';
                  echo '<button class="btn btn-info btn-xs btnExportDevisEnCours" title="Export Excel du devis" data-rid="' . $devis["rowid"] . '" data-libelle="' . $devis["libelle"] . '"><i class="fa fa-file-excel-o fa-lg"></i></button>';
                  echo '<button class="btn btn-info btn-xs btnExportDevisXMLEnCours" title="Export XML SAP du devis" data-rid="' . $devis["rowid"] . '" data-libelle="' . $devis["libelle"] . '"><i class="fa fa-scribd fa-lg"></i></button>';
                  $typBtn = "btn-success";
                  foreach ($aModel["medias"] as $media) {
                    if ($media["support_rowid"] == $devis["rowid"]) {
                      $typBtn = "btn-warning";
                      break;
                    }
                  }
                  echo '<button class="btn ' . $typBtn . ' btn-xs btnImportPDFEnCours" title="Import PDF SAP du devis" data-rid="' . $devis["rowid"] . '" data-libelle="' . $devis["libelle"] . '"><i class="fa fa-upload fa-lg"></i></button>';
                  if ($devis["fk_statut_devis"] == 7) {
                    // Le devis vient d'être validé par le RR, l'ADV doit l'envoyer au client et le passer en statut 20 "Envoyé et archivé"
                    echo '<button class="btn btn-default btn-xs btnDevisEnvoye" title="Vous avez envoyé ce devis au client et il est maintenant à archiver" data-rid="' . $devis["rowid"] . '"><i class="fa fa-envelope fa-lg"></i></button>';
                  }
                  if ($devis["fk_statut_devis"] == 4) {
                    // Le devis vient d'être envoyé par le RR à l'ADV, l'ADV peut encore le supprimer
                    echo '<button class="btn btn-danger btn-xs btnDeleteDevis" title="Ce devis peut être encore supprimé" data-rid="' . $devis["rowid"] . '"><i class="fa fa-trash fa-lg"></i></button>';
                  }
                  echo '</div>';
                  if ($devis["fk_statut_devis"] == 4) {
                    // Le devis est à traiter sur SAP
                    echo '<input type="checkbox" class="ml-2 exportXMLCheckbox" data-rid="' . $devis["rowid"] . '" title="Cocher ce devis pour l exporter au format XML pour SAP">';
                  }
                  echo '</td>';
                  echo '</tr>';
                  $i++;
                }
              }
              if ($i == 0) {
                echo '<tr><td colspan="10" class="text-center">Aucun devis à ce niveau</td></tr>';
              }
              echo '</tbody>';
              echo '</table>';
              echo '</div>';
              echo '</div>';
              $iDos++;
            }
            ?>
          </div>
        </div>

        <div class="col-md-3">
          <div id="chat-container-enCours">
            <div class="chat-bubbles" id="chat-bubbles-enCours">
            </div>
            <div class="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="chatBtnSendEnCours">
                    <use xlink:href="/pub/res/css/images/icons.svg#paperplane"></use>
                  </svg>
                </div>
              </div>

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


    <div role="tabpanel" class="tab-pane" id="tabArchives">
      <div class="row">
        <div class="col-md-9">
          <ul class="nav nav-tabs" role="tablist">
            <li role="presentation" class="active"><a href="#dosArchTous" aria-controls="dosArchTous" role="tab" data-toggle="tab">Tous</a></li>
          </ul>
          <?php
          $i = 0;
          $nbPerLine = 25;
          $totalDepts = count($aModel["dossiers"]);

          for ($line = 0; $line < 4; $line++) {
            echo '<ul class="nav nav-tabs" role="tablist">';
            $start = $line * $nbPerLine;
            $end = min($start + $nbPerLine, $totalDepts);

            for ($j = $start; $j < $end; $j++) {
              $dossier = $aModel["dossiers"][$j];
              $ceDossier = ($dossier["dossier"] == "") ? "?" : $dossier["dossier"];
              echo '<li role="presentation" class="dept-tab"><a href="#dosArch' . $j . '" aria-controls="dosArch' . $j . '" role="tab" data-toggle="tab">' . $ceDossier . '</a></li>';
            }
            echo '</ul>';
          }
          ?>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane p-0 active" id="dosArchTous">
              <div class="border cm-scrollbar cm-table-w-scroll table-responsive table-800">
                <table class="table table-responsive table-bordered table-fixed" id="tblDosArchTous">
                  <thead><tr>
                    <th class="header text-center clickable" scope="col" width="5%" data-sortable="true" data-sort-type="number" data-column-index="0">#</th>
                    <th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="date" data-column-index="1">Date Demande</th>
                    <th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="2">Resp. Régional</th>
                    <th class="header text-center clickable" scope="col" width="7%" data-sortable="true" data-sort-type="text" data-column-index="3">Code Etabliss.</th>
                    <th class="header text-center clickable" scope="col" width="15%" data-sortable="true" data-sort-type="text" data-column-index="4">Etablissement</th>
                    <th class="header text-center clickable" scope="col" width="5%" data-sortable="true" data-sort-type="number" data-column-index="5">CP</th>
                    <th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="6">Ville</th>
                    <th class="header text-center clickable" scope="col" width="8%" data-sortable="true" data-sort-type="text" data-column-index="7">Marché</th>
                    <th class="header text-center clickable" scope="col" width="5%" data-sortable="true" data-sort-type="text" data-column-index="8">Dép.</th>
                    <th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="number" data-column-index="9">Montant Total HT</th>
                    <th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="number" data-column-index="10">Marge totale</th>
                    <th class="header text-center" scope="col" width="10%">Actions</th>
                  </tr></thead>
                  <tbody id="tblBodyDosArchTous">
                    <?php
                    $i = 0;
                    foreach ($aModel["devisArchives"] as $devis) {
                      echo '<tr id="trArchTous_' . $devis["rowid"] . '">';
                      echo '<td class="text-center">' . $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["prenom"] . " " . $devis["nom"] . '</td>';
                      echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $devis["code"] . '</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"] . '">' . $libelle . '</td>';
                      echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $devis["cp"] . '</td>';
                      echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $ville . '</td>';
                      echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $devis["lib_marche"] . '</td>';
                      $dossierLabel = ($devis["dossier"] == "") ? "?" : $devis["dossier"];
                      echo '<td class="clickable celArchives text-center" data-rid="' . $devis["rowid"] . '">' . $dossierLabel . '</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="text-center">';
                      echo '<div class="btn-group">';
                      echo '<button class="btn btn-primary btn-xs btnViewDevisArchives" title="Consulter le devis" data-rid="' . $devis["rowid"] . '"><i class="fa fa-eye fa-lg"></i></button>';
                      echo '<button class="btn btn-info btn-xs btnExportDevisEnCours" title="Export Excel du devis" data-rid="' . $devis["rowid"] . '" data-libelle="' . $devis["libelle"] . '"><i class="fa fa-file-excel-o fa-lg"></i></button>';
                      $typBtn = "btn-success";
                      foreach ($aModel["medias"] as $media) {
                        if ($media["support_rowid"] == $devis["rowid"]) {
                          $typBtn = "btn-warning";
                          break;
                        }
                      }
                      echo '<button class="btn ' . $typBtn . ' btn-xs btnImportPDFEnCours" title="Consulter le PDF SAP du devis" data-rid="' . $devis["rowid"] . '" data-libelle="' . $devis["libelle"] . '"><i class="fa fa-file-pdf-o fa-lg"></i></button>';
                      echo '</div>';
                      echo '</td></tr>';
                      $i++;
                    }
                    if ($i == 0) echo '<tr><td colspan="12" class="center">Aucun devis archivé trouvé</td></tr>';
                    ?>
                  </tbody>
                </table>
              </div>
            </div>
            <?php
            $iDos = 0;
            foreach ($aModel["dossiers"] as $dossier) {
              $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 text-center clickable" scope="col" width="5%" data-sortable="true" data-sort-type="number" data-column-index="0">#</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="date" data-column-index="1">Date Demande</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="2">Resp. Régional</th>';
              echo '<th class="header text-center clickable" scope="col" width="7%" data-sortable="true" data-sort-type="text" data-column-index="3">Code Etabliss.</th>';
              echo '<th class="header text-center clickable" scope="col" width="20%" data-sortable="true" data-sort-type="text" data-column-index="4">Etablissement</th>';
              echo '<th class="header text-center clickable" scope="col" width="5%" data-sortable="true" data-sort-type="number" data-column-index="5">CP</th>';
              echo '<th class="header text-center clickable" scope="col" width="13%" data-sortable="true" data-sort-type="text" data-column-index="6">Ville</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="text" data-column-index="7">Marché</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="number" data-column-index="8">Montant Total HT</th>';
              echo '<th class="header text-center clickable" scope="col" width="10%" data-sortable="true" data-sort-type="number" data-column-index="9">Marge totale</th>';
              echo '<th class="header text-center" scope="col" width="10%">Actions</th>';
              echo '</tr></thead>';
              echo '<tbody id="tblBodyDosArch' . $iDos . '">';
              $libDossier = $dossier["dossier"];
              $i = 0;
              foreach ($aModel["devisArchives"] as $devis) {
                if ($devis["dossier"] == $libDossier) {
                  echo '<tr id="trArch_' . $devis["rowid"] . '">';
                  echo '<td class="text-center">' . $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["prenom"] . " " . $devis["nom"] . '</td>';
                  echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $devis["code"] . '</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"] . '">' . $libelle . '</td>';
                  echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $devis["cp"] . '</td>';
                  echo '<td class="clickable celArchives" data-rid="' . $devis["rowid"] . '">' . $ville . '</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="text-center">';
                  echo '<div class="btn-group">';
                  echo '<button class="btn btn-primary btn-xs btnViewDevisArchives" title="Consulter le devis" data-rid="' . $devis["rowid"] . '"><i class="fa fa-eye fa-lg"></i></button>';
                  echo '<button class="btn btn-info btn-xs btnExportDevisEnCours" title="Export Excel du devis" data-rid="' . $devis["rowid"] . '" data-libelle="' . $devis["libelle"] . '"><i class="fa fa-file-excel-o fa-lg"></i></button>';
                  $typBtn = "btn-success";
                  foreach ($aModel["medias"] as $media) {
                    if ($media["support_rowid"] == $devis["rowid"]) {
                      $typBtn = "btn-warning";
                      break;
                    }
                  }
                  echo '<button class="btn ' . $typBtn . ' btn-xs btnImportPDFEnCours" title="Consulter le PDF SAP du devis" data-rid="' . $devis["rowid"] . '" data-libelle="' . $devis["libelle"] . '"><i class="fa fa-file-pdf-o fa-lg"></i></button>';
                  echo '</div>';
                  echo '</td></tr>';
                  $i++;
                }
              }
              if ($i == 0) echo '<tr><td colspan="10" class="center">Aucun devis archivé trouvé sur ce département</td></tr>';
              echo '</tbody>';
              echo '</table>';
              echo '</div>';
              echo '</div>';
              $iDos++;
            }
            ?>
          </div>
        </div>
        <div class="col-md-3">
          <div id="chat-container-archives">
            <div class="chat-bubbles" id="chat-bubbles-archives">
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<?php
$content = ob_get_contents();
ob_clean();

ob_start();
?>
<div class="modal draggable fade" id="modalUploadPDF" tabindex="-1" role="dialog" aria-labelledby="modUploadPDFTitre" data-backdrop="static">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="modUploadPDFTitre">Importer le PDF SAP du devis</h4>
      </div>
      <div class="modal-body">
        <table id="tblPJ" class="table">
          <tbody>

          </tbody>
        </table>
        <form class="form-inline">
          <div class="row">
            <div class="col-md-12">
              <div class="form-group">
                <label for="txtUploadPDF">Document PDF</label>
                <input type="file" id="txtUploadPDF" name="txtUploadPDF" class="form-control" accept="application/pdf">
              </div>
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" id="btnUploadPDF">Importer</button>
        <button type="button" class="btn btn-default" id="btnClosePDF">Fermer</button>
      </div>
    </div>
  </div>
</div>

<div class="modal draggable fade" id="modalViewDevis" tabindex="-1" role="dialog" aria-labelledby="modViewDevisTitre" data-backdrop="static">
  <div class="modal-dialog modal-xl">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="modViewDevisTitre"></h4>
      </div>
      <div class="modal-body">
        <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="#tabdevis" aria-controls="tabdevis" role="tab" data-toggle="tab">2. Devis</a></li>
          <li role="presentation" id="panSpeciaux"><a href="#tabspeciaux" aria-controls="tabspeciaux" role="tab" data-toggle="tab">3. Produits spéciaux</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" class="form" role="presentation">
                <div class="row">
                  <div class="form-group">
                    <label class="control-label col-md-2" for="inp_num_opportunite">N° opportunité :</label>
                    <div class="col-md-3">
                      <input type="text" class="form-control" id="inp_num_opportunite" name="num_opportunite" disabled="disabled" />
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="form-group">
                    <label class="control-label col-md-2" for="inp_date_demande">Date demande :</label>
                    <div class="col-md-3">
                      <input type="text" class="form-control" id="inp_date_demande" name="date_demande" disabled="disabled" />
                    </div>
                    <label class="control-label col-md-2" for="inp_date_remise">A remettre au client le :</label>
                    <div class="col-md-3">
                      <input type="text" class="form-control" id="inp_date_remise" name="date_remise" disabled="disabled" />
                    </div>
                  </div>
                </div>
                <hr>
                <div class="row">
                  <div class="form-group">
                    <label class="control-label col-md-2">Nom du client :</label>
                    <div class="col-md-5">
                      <input type="text" class="form-control" id="inp_lib_client" name="lib_client" disabled="disabled" />
                    </div>
                    <label class="control-label col-md-2" for="inp_type_etablissement">Type de l'établissement :</label>
                    <div class="col-md-2">
                      <input type="text" class="form-control" id="inp_type_client" name="type_client" disabled="disabled" />
                    </div>
                  </div>
                </div>
                <div class="row">
                  <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" disabled="disabled" />
                    </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" disabled="disabled" />
                    </div>
                  </div>
                </div>
                <div class="row">
                  <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" disabled="disabled" />
                    </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" disabled="disabled" />
                    </div>
                  </div>
                </div>
                <div class="row">
                  <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" disabled="disabled" />
                    </div>
                  </div>
                </div>
                <hr />
                <div class="row">
                  <div class="form-group">
                    <label class="control-label col-md-2" for="inp_contact_nom">Contact :</label>
                    <div class="col-md-4">
                      <input type="text" class="form-control" id="inp_contact_nom" name="contact_nom" disabled="disabled" />
                      <p class="help-block">Nom du contact</p>
                    </div>
                    <div class="col-md-4">
                      <input type="text" class="form-control" id="inp_contact_prenom" name="contact_prenom" disabled="disabled" />
                      <p class="help-block">Prénom du contact</p>
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="form-group">
                    <label class="control-label col-md-2" for="inp_contact_fonction">Fonction du contact :</label>
                    <div class="col-md-4">
                      <input type="text" class="form-control" id="inp_contact_fonction" name="contact_fonction" disabled="disabled" />
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class=" form-group">
                    <label class="control-label col-md-2" for="inp_email">Email :</label>
                    <div class="col-md-4">
                      <input type="text" class="form-control" id="inp_email" name="email" disabled="disabled" />
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class=" form-group">
                    <label class=" control-label col-md-2" for="inp_telephone">Tél :</label>
                    <div class="col-md-3">
                      <input type="text" class="form-control" id="inp_telephone" name="telephone" disabled="disabled" />
                    </div>
                    <label class=" control-label col-md-2" for="inp_mobile">Mob :</label>
                    <div class="col-md-3">
                      <input type="text" class="form-control" id="inp_mobile" name="mobile" disabled="disabled" />
                    </div>
                  </div>
                </div>

                <div class="form-group">
                  <label for="fk_marche" class="control-label col-md-2">Marché :</label>
                  <div class="col-md-3">
                    <input type="text" class="form-control" id="inp_lib_marche" name="lib_marche" disabled />
                  </div>
                  <label for="inp_chk_devis_photos" class="control-label col-md-2">Devis avec photos :</label>
                  <input type="checkbox" class="form-control" name="chk_devis_photos" id="inp_chk_devis_photos" disabled />
                </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" disabled="disabled" />
                  </div>
                </div>

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

          <div role="tabpanel" class="tab-pane" id="tabdevis">
            <div class="container-fluid">
              <div class="row">
                <form class="form-inline" id="frmDevis">
                  <div class="col-md-9">
                    <div class="row">
                      <div class="col-md-12">
                        <table class="table">
                          <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>
                            </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"
                                  style="border-color: #8DB255!important; border-width: 4px;" />
                                <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"
                                  style="border-color: #DC3023!important; border-width: 4px;" />
                                <div class="input-group-addon">%</div>
                              </div>
                            </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%">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>
                  <div class="col-md-3">
                    <div class="row">
                      <div class="col-md-12">
                        <div class="well" style="background: #EEE;">
                          <h5><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>Franco de port</td>
                              <td id="tdFrancoPort" class="bold"></td>
                            </tr>
                            <tr>
                              <td>Garantie</td>
                              <td id="tdGarantie" class="bold"></td>
                            </tr>
                            <tr>
                              <td>Délai de livraison</td>
                              <td id="tdDelaiLivr" class="bold"></td>
                            </tr>
                            <tr>
                              <td>Remises commerciales</td>
                              <td id="tdRemisesCo" class="bold"></td>
                            </tr>
                          </table>
                        </div>
                      </div>
                    </div>
                  </div>
                </form>
              </div>
            </div>
          </div>

          <div role="tabpanel" class="tab-pane" id="tabspeciaux">
            <div class="container-fluid">
              <div class="row">
                <div class="form-group">
                  <label for="inp_chk_livr_multi" class="control-label col-md-2">Livraisons multiples :</label>
                  <div class="col-md-1">
                    <input type="checkbox" class="form-control" id="inp_chk_livr_multi" disabled />
                  </div>
                  <label class="control-label col-md-2" for="inp_nb_livr">Si oui, combien :</label>
                  <div class="col-md-1">
                    <input type="number" class="form-control" id="inp_nb_livr" disabled />
                  </div>
                  <label class="control-label col-md-2" 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" disabled />
                  </div>
                </div>
              </div>
              <hr>
              <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="10%">Code</th>
                          <th width="10%">Désignation</th>
                          <th width="10%">Qté</th>
                          <th width="10%">Surcoût</th>
                          <th width="10%">Echantillon</th>
                          <th width="10%">Date</th>
                          <th width="15%">Concurrent</th>
                          <th width="15%">Description</th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr>
                          <td><input type="text" class="form-control" id="inp_specialCode_1" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialLibe_1" disabled /></td>
                          <td><input type="number" class="form-control" id="inp_specialQte_1" disabled /></td>
                          <td><input type="number" class="form-control" id="inp_specialCout_1" disabled /></td>
                          <td><input type="checkbox" class="form-control" id="inp_chk_specialEchantillon_1" disabled /></td>
                          <td><input type="date" class="form-control" id="inp_specialDate_1" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialConcurrent_1" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialDescription_1" disabled /></td>
                        </tr>
                        <tr>
                          <td><input type="text" class="form-control" id="inp_specialCode_2" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialLibe_2" disabled /></td>
                          <td><input type="number" class="form-control" id="inp_specialQte_2" disabled /></td>
                          <td><input type="number" class="form-control" id="inp_specialCout_2" disabled /></td>
                          <td><input type="checkbox" class="form-control" id="inp_chk_specialEchantillon_2" disabled /></td>
                          <td><input type="date" class="form-control" id="inp_specialDate_2" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialConcurrent_2" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialDescription_2" disabled /></td>
                        </tr>
                        <tr>
                          <td><input type="text" class="form-control" id="inp_specialCode_3" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialLibe_3" disabled /></td>
                          <td><input type="number" class="form-control" id="inp_specialQte_3" disabled /></td>
                          <td><input type="number" class="form-control" id="inp_specialCout_3" disabled /></td>
                          <td><input type="checkbox" class="form-control" id="inp_chk_specialEchantillon_3" disabled /></td>
                          <td><input type="date" class="form-control" id="inp_specialDate_3" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialConcurrent_3" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialDescription_3" disabled /></td>
                        </tr>
                        <tr>
                          <td><input type="text" class="form-control" id="inp_specialCode_4" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialLibe_4" disabled /></td>
                          <td><input type="number" class="form-control" id="inp_specialQte_4" disabled /></td>
                          <td><input type="number" class="form-control" id="inp_specialCout_4" disabled /></td>
                          <td><input type="checkbox" class="form-control" id="inp_chk_specialEchantillon_4" disabled /></td>
                          <td><input type="date" class="form-control" id="inp_specialDate_4" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialConcurrent_4" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialDescription_4" disabled /></td>
                        </tr>
                        <tr>
                          <td><input type="text" class="form-control" id="inp_specialCode_5" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialLibe_5" disabled /></td>
                          <td><input type="number" class="form-control" id="inp_specialQte_5" disabled /></td>
                          <td><input type="number" class="form-control" id="inp_specialCout_5" disabled /></td>
                          <td><input type="checkbox" class="form-control" id="inp_chk_specialEchantillon_5" disabled /></td>
                          <td><input type="date" class="form-control" id="inp_specialDate_5" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialConcurrent_5" disabled /></td>
                          <td><input type="text" class="form-control" id="inp_specialDescription_5" disabled /></td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>

        </div>
      </div>
      <div class="modal-footer" style="text-align: left;">
        <?php
        echo '<form id="frmComment" class="form-inline" role="presentation" >';
        echo '<label for="inpComment">Commentaire :</label>';
        echo '<input type="text" class="form-control mr-1" id="inpComment" name="inpComment" value="" style="width: 60%;" />';
        echo '<button type="button" class="btn btn-success" id="btnSaveComment">Enregistrer un commentaire</button>';
        echo '<button type="button" class="btn btn-default right" id="btnCloseModViewDevis">Fermer</button>';
        echo '</form>';
        ?>
      </div>
    </div>
  </div>
</div>
</div>
<?php
$modal = ob_get_contents();
ob_clean();

ob_start();
echo '<script src="/pub/res/js/jsap.js"></script>';
echo '<script src="/pub/res/js/jchat.js"></script>';
$jscript = ob_get_contents();
ob_end_clean();
require_once $Route->_layout;
