<%@ language="javascript"%>
<% /*
     $Revision$
     $Id$
*/%>
<!--#include file="../../appl/Shared/common.inc"-->
<% FCLTHeader.Set({root: "../../appl/"}); %>
<!--#include file="../../appl/Shared/resultset_table_v2.inc" -->
<%
var sql="";
var highlight_arr = getQParamIntArray("highlight", []); // Comma-separated room_key_list (terrains). Optional
var floorKey = getQParamInt("vKey", -1);

var outputmode = getQParamInt("outputmode", 0);
var showall    = getQParamInt("showall", 0) == 1;
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script>
      function conn_DoSchContract(alg_locatie_key)
      {
        FcltMgr.openModalDetail('../../../' + '<%=custpath%>' + '/schoonmaak_info.asp?lkey='+alg_locatie_key, 'Schoonmaakcontract Info');
      }

      function conn_DoSchOpm(alg_ruimte_key)
      {
        FcltMgr.openModalDetail('../../../' + '<%=custpath%>' + '/schoonmaak_opm.asp?rkey='+alg_ruimte_key, 'Opmerking bij schoonmaakcontract');
      }
    </script>
  </head>

  <body class="tabpage">
    <form name='u2'>
<%
      // connspecifiek
      // in _conn.inc: factor_key=80; // alg_kenmerk_key van schoonmaakfactor van een gebouw
      // in _conn.inc: schtarief=" DECODE(R.SCHOON,'ISS',18.66,'Berkel',19.30,'VLS',18.75,'NOVON',19.06,0) ";
      if (floorKey != -1)
      {
        sql = " SELECT r.ruimtenr"
            + "       , r.oppervlakte"
            + "       , r.vloersoort"
            + "       , r.omschrijving"
            + "       , r.ruimtesoort"
            + "       , r.schoon"
            + "       , r.ruimte_dicht_datum"
            + "       , r.ruimte_open_datum"
            + "       , TO_CHAR(R.kengetal, '90D9999') kengetal"
            + "       , TO_CHAR(R.Totaal,'99999D99') totaal"
            + "       , r.programma"
            + "       , r.hasopm"
            + "       , r.inhuur"
            + "       , r.uitbeheer"
            + "       , r.alg_ruimte_key"
            + "       , r.alg_locatie_key"
            + "       , r.sch_document"
            + "    FROM (SELECT sch.bestek"
            + "               , alg_r.alg_ruimte_key alg_ruimte_key"
            + "               , alg_g.alg_locatie_key alg_locatie_key"
            + "               , alg_r.alg_ruimte_omschrijving omschrijving"
            + "               , (SELECT alg_srtruimte_code FROM alg_srtruimte sr WHERE sr.alg_srtruimte_key = alg_r.alg_srtruimte_key) AS ruimtesoort"
            + "               , alg_g.alg_gebouw_code || '-' || TO_CHAR(alg_v.alg_verdieping_volgnr) || '-' || alg_r.alg_ruimte_nr ruimtenr"
            + "               , sch.oppervlakte"
            + "               , sch.vloersoort"
            + "               , sch.tot_ruimte_bedrag as totaal"
            + "               , sch.schoon"
            + "               , sch.programma"
            + "               , sch.frequentie"
            + "               , sch.rs"
            + "               , sch.vs"
            + "               , sch.kengetal"
            + "               , sch.ruimte_dicht_datum"
            + "               , sch.ruimte_open_datum"
            + "               , sch.inhuur"
            + "               , sch.uitbeheer"
            + "               , sch.sch_document"
            + "               , sch.opm as hasopm"
            + "            FROM alg_gebouw alg_g"
            + "               , alg_verdieping alg_v"
            + "               , alg_v_aanwezigruimte alg_r"
            + "               , conn_v_schoongeg2 sch"
            + "           WHERE alg_v.alg_verdieping_key = " + floorKey
            + "             AND alg_v.alg_verdieping_key = alg_r.alg_verdieping_key"
            + "             AND alg_g.alg_gebouw_key = alg_v.alg_gebouw_key"
            + "             AND alg_r.alg_ruimte_key = sch.alg_ruimte_key"
            + "      ) R                                         "
            + (highlight_arr.length > 0 && highlight_arr.join(",").indexOf("-1") == -1
              ? " WHERE r.alg_ruimte_key IN (" + highlight_arr.join(",") + ")"
              : "")
            + " ORDER BY 1";
      }

      function refCnt(oRs)
      {
        var txt = (oRs("totaal").value);
        if (!txt) return "";

        return "<a title='Klik voor overzicht hele complex' " +
               "   href='javascript:conn_DoSchContract(" + oRs("alg_locatie_key").value + ")'>" + txt + "</a>";
      }

      function refSchOpm(oRs)
      {
        var txt = (oRs("HasopM").value);
        if (txt!='1') return "";

        return "<a title='Klik voor opmerkingen' " +
               "   href='javascript:conn_DoSchOpm(" + oRs("alg_ruimte_key").value + ")'>Opm</a>";
      }

      function refDoc(oRs)
      {
        if (!oRs("Programma").value) return "";

        return "<a href='" + safe.htmlattr(oRs("sch_document").value) + "' target=_new>"
             + safe.htmlattr(oRs("Programma").value) + "</a>"
      }

      var rst = new ResultsetTable({ sql: sql,
                                     ID : "cadschtable",
                                     keyColumn: "Ruimtenr",
                                     title: L("lcl_cleaning_h"),
                                     outputmode: outputmode,
                                     showAll: showall
                                   });

      rst.addColumn(new Column({caption: L("lcl_obj_inf_room"), content: "ruimtenr"}));
      rst.addColumn(new Column({caption: L("lcl_opp"), content: "oppervlakte"}));
      rst.addColumn(new Column({caption: "Vloersoort", content: "vloersoort"}));
      rst.addColumn(new Column({caption: L("lcl_descr"), content: "omschrijving"}));
      rst.addColumn(new Column({caption: "Ruimtesoort", content: "ruimtesoort"}));
      rst.addColumn(new Column({caption: "Schoonmaakbedrijf", content: "schoon"}));
      rst.addColumn(new Column({caption: "Dicht per", content: "ruimte_dicht_datum"}));
      rst.addColumn(new Column({caption: "Open per", content: "ruimte_open_datum"}));
      rst.addColumn(new Column({caption: "Kengetal", content: "kengetal"}));
      rst.addColumn(new Column({caption: "Kosten/m", content: refCnt}));
      rst.addColumn(new Column({caption: "Programma", content: refDoc}));
      rst.addColumn(new Column({caption: "Opm", content: refSchOpm}));
      rst.addColumn(new Column({caption: "Inhuur", content: "inhuur"}));
      rst.addColumn(new Column({caption: "Uitbeheer", content: "uitbeheer"}));

      var cnt = rst.processResultset();
%>
    </form>
  </body>
</html>
