<?php
session_start();

if (isset($_SESSION['_session']['user']) &&  (time() - $_SESSION['_session']['LAST_ACTIVITY']  < $_SESSION['_session']['koha'])) {

  $_SESSION['_session']['LAST_ACTIVITY']  = time();

  if ($_SESSION['_session']['submit_service_request'] == 1) {

    if (isset($_SERVER['QUERY_STRING'])) {
      $visid = $_GET['vid'];
    }
    if (!isset($visid)) {
      $ref = "<script>
  window.location.href = 'dashboard.php';
</script>";
      echo $ref;
    }
    require 'header.php';
?>
    <style type="text/css">
      .btn-clipboard {
        position: absolute;
        top: 4.65rem;
        right: 0.65rem;
        padding: 0.25rem 0.5rem;
        color: #0d6efd;
        background-color: #fff;
        border: 1px solid;
        border-radius: 0.25rem;
      }

      @media print {
        .myDivToPrint {
          background-color: white;
          height: 100%;
          width: 100%;
          position: fixed;
          top: 0;
          left: 0;
          margin: 0;
          padding: 15px;
          font-size: 14px;
          line-height: 18px;
        }
      }
    </style>
    
    <div class="content" id="canvas" style="margin: 0">

      <div id="printothis" class="myDivToPrint container">
     
        <div style="text-align: end;  margin-top: 24px"> <button id="hell" class="btn">Printo</button><button id="para" onclick="para();" class="btn">Para</button>
          <button id="next" onclick="next()" class="btn">Tjetra</button>
        </div>
        <div class="card" style="margin-top: 0px">

          <!-- start  start  start  start  start  start  start  start  start  start  start  start  start  start -->
          <div class="row">

            <div class="col col-md-12">
              <nav class="navbar navbar-light bg-light justify-content-between" style="padding: 0; box-shadow: unset">
                <img src="../../../images/Atommed.png" style="height: auto; max-width: 220px; padding-left: 30px">
                <a style="font-size: 11px; padding-right: 30px">Adresa: Rr.Cen Dugolli, Ferizaj <br> Tel.:+383 (0) 49 530 551 <br> +383 (0) 49 530 459 <br> atommed@hotmail.com</a>
              </nav>
            </div>
          </div>

          <div class="col col-md-12" style="width: auto; border: 2px solid grey;">
            <p style="display: flex; justify-content: center; font-weight: 700; font-size: 14px; padding: 0; margin:0;">RAPORT SERVISI</p>
          </div>

          <br>

          <div class="col col-md-12">
            <h6 style="margin: 0">Të dhënat e klientit</h6>
            <hr style="margin: 0">
            <div class="row" id="clientsdata">
              <div class="col-md-4">
                <p>Laboratori:<br>
                  <strong id="labi"></strong>
                </p>
              </div>
              <div class="col-md-4">
                <p>Personi Përgjegjës:<br>
                  <strong id="emrimbiemri"></strong>
                </p>
              </div>
              <div class="col-md-4">
                <p>Departamenti:<br>
                  <select class="form-control" id="dep">
                    <option class="form-control" style="color: red;"> -Zgjedh Departamentin -</option>
                    <option class="form-control" value="Biokimi">Biokimi</option>
                    <option class="form-control" value="Mikro">Mikro</option>
                    <option class="form-control" value="Gjenetikë">Gjenetikë</option>
                  </select>
              </div>
            </div>
          </div>

          <br>

          <div class="col col-md-12">
            <h6 style="margin: 0">Të dhënat e Kërkesës</h6>
            <hr style="margin: 0">
            <!-- qikjo ka me kon nje loop se kerkesa mundet me kon me ma shume se nje pajisje -->
            <div class="row" id="devicesdata">
              <div class="col-md-4">
                <p>Aparati:<br>
                  <strong id="aparati"></strong>

                </p>
              </div>
              <div class="col-md-4">
                <p>Serviset:<br>
                  <strong id="serviset"></strong>
                </p>
              </div>

              <div class="col-md-2">
                <p>Versioni i programit<br>
                  <strong id="vers"></strong>
                </p>
              </div>
              <div class="col-md-2">
                <p>Numri Serik:<br>
                  <strong id="nrserik"></strong>
                </p>
              </div>
            </div>
          </div>

          <br>

          <div class="col col-md-12">
            <div class="col" style="width: auto;border: 2px solid grey;border-radius: 12px; ">
              <label>Përshkrimi i problemit në kërkesë - Komenti</label>

              <div class="col col-md-12">
                <textarea rows="2" class="form-control" id="pershkrimi" style="background: transparent; overflow: hidden" disabled> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.  It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.   It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
              </textarea>
              </div>
            </div>
          </div>
          <br>
          <div class="col col-md-12">
            <div class="row" id="devicescheckbox">
              <div class="col-md-2"><label><input type="checkbox" id="Kontrate" name="" onclick='return false;'> Kontratë</label></div>
              <div class="col-md-2"><label><input type="checkbox" id="Falas" name="" onclick='return false;'> Falas </label></div>
              <div class="col-md-2"><label><input type="checkbox" id="Garancion" name="" onclick='return false;'> Garancion</label></div>
              <div class="col-md-4"><label><input type="checkbox" id="Reagjentesh" name="" onclick='return false;'> Përdorim Reagjentësh</label></div>
              <div class="col-md-2"><label><input type="checkbox" id="Qera" name="" onclick='return false;'> Qera</label></div>
            </div>
          </div>

          <br>

          <div class="col col-md-12">
            <h6 style="margin: 0">Përshkrimi i problemit</h6>
            <hr style="margin: 0">
            <div class="row" id="checkboxforproblem">
              <div class="col-md-2"><label><input type="checkbox" class="perprob" id="Teknik" name="" onclick='return false;'> Teknik</label></div>
              <div class="col-md-2"><label><input type="checkbox" class="perprob" id="Kimik" name="" onclick='return false;'> Kimik </label></div>
              <div class="col-md-2"><label><input type="checkbox" class="perprob" id="operimi" name="" onclick='return false;'> Programi/ operimi</label></div>
              <div class="col-md-2"><label><input type="checkbox" class="perprob" id="Procedurë" name="" onclick='return false;'> Procedurë</label></div>
              <div class="col-md-2"><label><input type="checkbox" class="perprob" id="Tjetër" name="" onclick='return false;'> Tjetër</label></div>
              <div class="col-md-2"><label><input type="checkbox" class="perprob" id="problem" name="" onclick='return false;'> Nuk u raportua problem</label></div>
            </div>
          </div>

          <br>

          <div class="col col-md-12">
            <h6 style="margin: 0">Lloji i vizitës</h6>
            <hr style="margin: 0">
            <div class="row" id="llojivizites">
              <div class="col-md-2"><label><input type="checkbox" class="vizita" id="Mirëmbajtje" name="" onclick='return false;'> Mirëmbajtje</label></div>
              <div class="col-md-2"><label><input type="checkbox" class="vizita" id="Urgjent" name="" onclick='return false;'> Urgjent </label></div>
              <div class="col-md-2"><label><input type="checkbox" class="vizita" id="Trajnim" name="" onclick='return false;'> Trajnim</label></div>
              <div class="col-md-2"><label><input type="checkbox" class="vizita" id="Instalim" name="" onclick='return false;'> Instalim</label></div>
              <div class="col-md-4"><label><input type="checkbox" class="vizita" id="Tjetërvz" name="" onclick='return false;'> Tjetër <input type="text" class="form-control" style="border: inherit"></label> </div>
            </div>
          </div>

          <br>

          <div class="col col-md-12">
            <h6 style="margin: 0">Detaje</h6>
            <hr style="margin: 0">
            <div class="row" id="detaje">
              <div class="col-md-2">Data sot?<input type="date" id="datasot" class="form-control" name="" disabled></div>
              <div class="col-md-2">Koha e ardhjes<input type="text" id="kohaardhjes" class="form-control" name="" disabled></div>
              <div class="col-md-2">Koha e largimit<input type="text" id="kohalarg" class="form-control" name="" disabled></div>
              <div class="col-md-2">Trajnim<input type="text" id="trajnimdata" class="form-control" name="" disabled> </div>
              <div class="col-md-2">Instalim<input type="text" id="instalimdata" class="form-control" name="" disabled> </div>
              <div class="col-md-2">Tjetër<input type="text" id="tjeterdata" class="form-control" name="" disabled></div>
            </div>
            <button onClick="$('#getDiv').toggle()" class="btn btn-clipboard" title="" data-bs-original-title="Shto rubrikë për detaje"><i class="material-icons">add</i></button>
          </div>
          <!-- <button onClick="$('#getDiv').toggle()" class="btn btn-xs"><i class="material-icons">add</i></button>  -->
          <!-- jquery me shfaq -->

          <br>
          <!-- shto edhe nje div nese ka nevoje -->
          <div class="col col-md-12" id="getDiv" style="display: none;">
            <h6 style="margin: 0">Detaje</h6>
            <hr style="margin: 0">
            <div class="row" id="detaje">
              <div class="col-md-2">Data sot?<input type="date" class="form-control" name="" disabled></div>
              <div class="col-md-2">Koha e ardhjes<input type="text" class="form-control" name="" disabled></div>
              <div class="col-md-2">Koha e largimit<input type="text" class="form-control" name="" disabled></div>
              <div class="col-md-2">Trajnim<input type="text" class="form-control" name="" disabled> </div>
              <div class="col-md-2">Instalim<input type="text" class="form-control" name="" disabled> </div>
              <div class="col-md-2">Tjetër<input type="text" class="form-control" name="" disabled></div>
            </div>
          </div>

          <br>

          <div class="col col-md-12">
            <div class="row" id="detaje2">
              <div class="col-md-2">Koha në kompani<input type="text" id="Kohakompani" class="form-control" name="" disabled></div>
              <div class="col-md-2">Koha në laborator<input type="text" id="Kohalab" class="form-control" name="" disabled></div>
              <div class="col-md-2">Koha e udhëtimit<input type="text" id="Kohaudhe" class="form-control" name="" disabled></div>
              <div class="col-md-2">Faturime<input type="text" id="Faturime" class="form-control" name="" disabled> </div>
              <div class="col-md-2">TT<input type="text" id="TT" class="form-control" name="" disabled> </div>
              <div class="col-md-2">Numri i faturës<input type="text" id="Numrifatures" class="form-control" name="" disabled></div>
            </div>
          </div>

          <br>

          <div class="col col-md-12">
            <h6 style="margin: 0">Përshkrimi i punimeve</h6>
            <hr style="margin: 0">
            <div class="row">
              <div class="col-md-7">
                <textarea id="pershkrimipunes" class="form-control" disabled> </textarea>
              </div>
              <div class="col-md-3">
                <textarea id="Testetekryera" class="form-control" disabled>  </textarea>
              </div>
              <div class="col-md-2">
                <textarea id="kohapershkrim" class="form-control" disabled>  </textarea>
              </div>
              <div class="col col-md-12" style="padding-top: 5px">
                <input id="Aparaticheck" type="checkbox" onclick='return false;' > Aparati u dorëzua në gjendje të mirë pune
              </div>
            </div>
          </div>

          <br>
          <div class="col col-md-12">
            <div class="row">
              <div class="col-md-6">
                <textarea id="Shenimevizit" class="form-control resizable" disabled></textarea>
              </div>
              <div class="col-md-6">
                <textarea id="materialekonsumi" class="form-control resizable" name="text" disabled> </textarea>
              </div>
            </div>
          </div>

          <!-- <textarea id="body" style="width: 400px;"></textarea> -->

          <br>
          <nav class="navbar navbar-light bg-light justify-content-between" style="padding: 0; box-shadow: unset">
            <img src="../assets/img/vulafake.png" style="height: auto; max-width: 180px; padding-left: 30px">
            <label>Atommmed <?php echo date("d.m.Y") ?></label>
            <img src="../assets/img/vulafake.png" style="height: auto; max-width: 180px; padding-right: 30px">
          </nav>
          <!-- end  end  end  end  end  end  end  end  end  end  end  end  end  end  end  end  end  end  end -->
        </div> <!-- card -->
      </div> <!-- container -->


     

    </div> <!-- content -->
    <script>
      id = <?php echo $visid; ?>;
      paisja = 0;

      function next() {
        paisja += 1;
        getpaisjen();
        $('#para').attr('disabled', false);
      }

      function para() {
        paisja -= 1;
        getpaisjen();
        $('#next').attr('disabled', false);
      }
      $.ajax({
        url: url + "/getbyvisit/" + id,
        headers: {
          'api_token': token
        },
        type: 'GET',
        success: function(data, status) {
          $('#emrimbiemri').empty();
          $('#labi').empty();
          $('#pershkrimi').empty();
          $('#emrimbiemri').append(data[0].emri + ' ' + data[0].mbiemri);
          $('#labi').append(data[0].emri_institutit);


          //   ' <div class="col-md-3">' +
          //   '<p>Emri Laboratorit<br> <strong>' +  + '</strong> </p>' +
          //   '</div>' +
          //   '<div class="col-md-3">' +
          //   '<p>Personi pergjegjes<br> <strong>' + data[0].emri + ' ' + data[0].mbiemri + '</strong></p>' +
          //   '</div>' +
          //   '<div class="col-md-3">' +
          //   '<p>Qyteti<br> <strong>' + data[0].emri_qytetit + '</strong> </p>' +
          //   '</div>' +
          //   '<div class="col-md-3">' +
          //   '<p>Prioriteti<br> <strong style="color: red">' + data[0].prioriteti + '</strong> </p>' +
          //   '</div>'
          // );
          $('#pershkrimi').val(data[0].pershkrimi);
          $('#pershkrimi').attr('rows', data[0].pershkrimi.length / 90);

        }
      });

      function getpaisjen() {
        $.ajax({
          url: url + "/getpaisjevisit/" + id,
          headers: {
            'api_token': token
          },
          type: 'GET',
          success: function(data, status) {
            if ((paisja + 2) > data.length) {
              $('#next').attr('disabled', true);

            }
            if (paisja === 0) {
              $('#para').attr('disabled', true);

            }
            i = data[paisja].emri_pajisjes;

            shfaqpaisje(id, data[paisja].paisjaid, paisja);
            document.getElementById("aparati").innerHTML = i;
            $('#vers').empty();
            $('#vers').append(data[paisja].versioni_programit);
            $('#nrserik').empty();
            $('#nrserik').append(data[paisja].numri_serik);


          }
        });
      }

      getpaisjen();



      function shfaqpaisje(id, sid, r) {

        $('.clicked').removeClass("clicked");
        $('#paisjaa' + r).addClass("clicked");
        $.ajax({
          url: url + "/getservisit/" + id + "/" + sid,
          headers: {
            'api_token': token
          },
          type: 'GET',
          success: function(data, status) {
            if (data[0].Kontrat === 1) {
              $('#Kontrate').prop("checked", true);
            } else {
              $('#Kontrate').prop("checked", false);
            }
            if (data[0].Falas === 1) {
              $('#Falas').prop("checked", true);
            } else {
              $('#Falas').prop("checked", false);
            }
            if (data[0].Garancion === 1) {
              $('#Garancion').prop("checked", true);
            } else {
              $('#Garancion').prop("checked", false);
            }
            if (data[0].Reagjentesh === 1) {
              $('#Reagjentesh').prop("checked", true);
            } else {
              $('#Reagjentesh').prop("checked", false);
            }
            if (data[0].Qera === 1) {
              $('#Qera').prop("checked", true);
            } else {
              $('#Qera').prop("checked", false);
            }
            if (data[0].pershkrimiproblemit != null) {
              if (data[0].pershkrimiproblemit.includes('Teknik')) {
                $('#Teknik').prop("checked", true);
              } else {
                $('#Teknik').prop("checked", false);
              }

              if (data[0].pershkrimiproblemit.includes('Kimik')) {
                $('#Kimik').prop("checked", true);
              } else {
                $('#Kimik').prop("checked", false);
              }
              if (data[0].pershkrimiproblemit.includes('operimi')) {
                $('#operimi').prop("checked", true);
              } else {
                $('#operimi').prop("checked", false);
              }
              if (data[0].pershkrimiproblemit.includes('Procedurë')) {
                $('#Procedurë').prop("checked", true);
              } else {
                $('#Procedurë').prop("checked", false);
              }
              if (data[0].pershkrimiproblemit.includes('Tjetër')) {
                $('#Tjetër').prop("checked", true);
              } else {
                $('#Tjetër').prop("checked", false);
              }
              if (data[0].pershkrimiproblemit.includes('problem')) {
                $('#problem').prop("checked", true);
              } else {
                $('#problem').prop("checked", false);
              }
            }
            if (data[0].llojivizites != null) {
              if (data[0].llojivizites.includes('Mirëmbajtje')) {
                $('#Mirëmbajtje').prop("checked", true);
              } else {
                $('#Mirëmbajtje').prop("checked", false);
              }
              if (data[0].llojivizites.includes('Urgjent')) {
                $('#Urgjent').prop("checked", true);
              } else {
                $('#Urgjent').prop("checked", false);
              }
              if (data[0].llojivizites.includes('Trajnim')) {
                $('#Trajnim').prop("checked", true);
              } else {
                $('#Trajnim').prop("checked", false);
              }
              if (data[0].llojivizites.includes('Instalim')) {
                $('#Instalim').prop("checked", true);
              } else {
                $('#Instalim').prop("checked", false);
              }
              if (data[0].llojivizites.includes('Tjetërvz')) {
                $('#Tjetërvz').prop("checked", true);
              } else {
                $('#Tjetërvz').prop("checked", false);
              }
            }
            if (data[0].datasot != null) {
              $('#datasot').val(data[0].datasot);
            }
            if (data[0].kohaardhjes != null) {
              $('#kohaardhjes').val(data[0].kohaardhjes);
            }
            if (data[0].kohalargimit != null) {
              $('#kohalarg').val(data[0].kohalargimit);
            }
            if (data[0].Trajnim != null) {
              $('#trajnimdata').val(data[0].Trajnim);
            }
            if (data[0].Instalim != null) {
              $('#instalimdata').val(data[0].Instalim);
            }
            if (data[0].Tjetërdetaje != null) {
              $('#tjeterdata').val(data[0].Tjetërdetaje);
            }
            if (data[0].Kohakompani != null) {
              $('#Kohakompani').val(data[0].Kohakompani);
            }
            if (data[0].Kohalab != null) {
              $('#Kohalab').val(data[0].Kohalab);
            }
            if (data[0].Kohaudhe != null) {
              $('#Kohaudhe').val(data[0].Kohaudhe);
            }
            if (data[0].Faturime != null) {
              $('#Faturime').val(data[0].Faturime);
            }
            if (data[0].TT != null) {
              $('#TT').val(data[0].TT);
            }
            if (data[0].Numrifatures != null) {
              $('#Numrifatures').val(data[0].Numrifatures);
            }
            if (data[0].pershkrimipunes != null) {
              $('#pershkrimipunes').val(data[0].pershkrimipunes);
            }
            if (data[0].Testetekryera != null) {
              $('#Testetekryera').val(data[0].Testetekryera);
            }
            if (data[0].kohapershkrim != null) {
              $('#kohapershkrim').val(data[0].kohapershkrim);
            }
            if (data[0].Shenimevizit != null) {
              $('#Shenimevizit').val(data[0].Shenimevizit);
            }
            if (data[0].materialekonsumi != null) {
              $('#materialekonsumi').val(data[0].materialekonsumi);
            }

            if (data[0].Aparaticheck === 1) {
              $('#Aparaticheck').prop("checked", true);
            } else {
              $('#Aparaticheck').prop("checked", false);
            }
            i = '';
            for (var r in data) {
              i += data[r].service_name + " ,";
            }
            str = i.slice(0, -1);
            document.getElementById("serviset").innerHTML = str;

          }
        });
      }
    </script>
    <script type="text/javascript">
      $('.resizable').each(function() {
        this.setAttribute('style', 'height: 70px !important;overflow-y:hidden;');
      }).on('input', function() {
        this.style.height = 'auto';
        $('.resizable').attr('style', 'height: ' + (this.scrollHeight) + 'px !important;overflow-y:hidden;');

      });


      $('#hell').click(function() {
        window.open(
  'raportpdf.php?vid='+id,
  '_blank' // <- This is what makes it open in a new window.
);

      });
    </script>

<?php require 'footer.php';
  }   else
  { 
    header("location:dashboard.php");
  } 
} else {
  header("location:../logout.php");
}
?>