<%@ language="javascript"%>
<% /*
     $Revision$
     $Id$
*/%>
<!--#include file="../../appl/Shared/common.inc"-->
<!--#include file="../../appl/Shared/resultset_table_v2.inc" -->
<%
var sql = "";
var names = new Array();
var floorKey = getQParamInt("vKey", -1);
var highlight_arr = getQParamIntArray("highlight", []);
var outputmode = getQParamInt("outputmode", 0);
var showall    = getQParamInt("showall", 0) == 1;
%>

<html>
  <head>
<%  FCLTHeader.Generate({ outputmode: outputmode, root: "../../appl/" }); %>
    <script type="text/javascript">
      function onClickDoc(fn)
      {
        FcltMgr.openDetail("<%S('image_path_virtual')%>/" + fn, "Schoonmaakprogramma");
      }
    </script>
  </head>

  <body  class="tabpage">
<%
    // akzaspecifiek
    if (floorKey != -1)
    {
      sql = " SELECT r.alg_ruimte_key"
          + "      , r.alg_ruimte_aanduiding ruimtenr"
          + "      , r.alg_ruimte_bruto_vloeropp opp"
          + "      , va.fac_usrdata_omschr vloerafwerking"
          + "      , sc.alg_onrgoedkenmerk_waarde schoonmaakdocument"
          + "      , nn.fac_usrdata_omschr schoonmaakniveau"
          + " FROM (SELECT alg_r.alg_ruimte_key alg_ruimte_key"
          + "            , alg_r.alg_ruimte_omschrijving alg_ruimte_omschrijving"
          + "            , alg_s.alg_srtruimte_omschrijving alg_srtruimte_omschrijving"
          + "            , alg_r.alg_ruimte_bruto_vloeropp alg_ruimte_bruto_vloeropp"
          + "            , alg_g.alg_gebouw_code || '-' || TO_CHAR(alg_v.alg_verdieping_code) || '-' || alg_r.alg_ruimte_nr alg_ruimte_aanduiding"
          + "         FROM alg_gebouw alg_g"
          + "            , alg_verdieping alg_v"
          + "            , alg_v_aanwezigruimte ALG_R"
          + "            , alg_srtruimte ALG_S"
          + "        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_srtruimte_key != 961"   // 'Fictieve ruimte'
          + "          AND alg_r.alg_srtruimte_key = alg_s.alg_srtruimte_key(+)) r"
          + "    , (SELECT rr.alg_ruimte_key"
          + "            , ud.fac_usrdata_omschr"
          + "         FROM alg_onrgoedkenmerk ok"
          + "            , fac_usrdata ud"
          + "            , fac_kenmerkdomein rk"
          + "            , alg_kenmerk k"
          + "            , alg_v_aanwezigruimte rr"
          + "        WHERE rk.fac_usrtab_key = ud.fac_usrtab_key"
          + "          AND k.fac_kenmerkdomein_key = rk.fac_kenmerkdomein_key"
          + "          AND TO_CHAR(ud.fac_usrdata_key) = ok.alg_onrgoedkenmerk_waarde"
          + "          AND k.alg_kenmerk_key = 2"
          + "          AND rr.alg_ruimte_key = ok.alg_onrgoed_key) va"
          + "    , (SELECT rr.alg_ruimte_key"
          + "            , ud.fac_usrdata_omschr"
          + "         FROM alg_onrgoedkenmerk ok"
          + "            , (SELECT * FROM fac_usrdata WHERE fac_usrtab_key = 470) ud"
          + "            , alg_kenmerk k"
          + "            , alg_v_aanwezigruimte rr"
          + "        WHERE TO_CHAR(ud.fac_usrdata_key) = ok.alg_onrgoedkenmerk_waarde"
          + "          AND k.alg_kenmerk_key = 1001"
          + "          AND rr.alg_ruimte_key = ok.alg_onrgoed_key) nn"
          + "    , (SELECT rr.alg_ruimte_key"
          + "            , ok.alg_onrgoedkenmerk_waarde"
          + "         FROM alg_onrgoedkenmerk ok"
          + "            , alg_kenmerk k"
          + "            , alg_v_aanwezigruimte rr"
          + "        WHERE k.alg_kenmerk_key = 1020"
          + "          AND k.ALG_KENMERK_KEY = ok.alg_kenmerk_key"
          + "          AND rr.alg_ruimte_key = ok.alg_onrgoed_key) sc"
          + " WHERE va.alg_ruimte_key(+) = r.alg_ruimte_key"
          + "   AND sc.alg_ruimte_key(+) = r.alg_ruimte_key"
          + "   AND nn.alg_ruimte_key(+) = r.alg_ruimte_key"
          + (highlight_arr.length > 0 && highlight_arr.join(",").indexOf("-1") == -1
            ? " AND r.alg_ruimte_key IN (" + highlight_arr.join(",") + ")"
            : "")
          + " ORDER BY 1";
    }

    function refDoc(oRs)
    {
      return safe.htmlattr(oRs("schoonmaakdocument").value) == null? "" :  "<a href='" + 'javascript:onClickDoc("' + safe.jsstring(oRs("schoonmaakdocument").value) + '")' + "'>" + safe.htmlattr(oRs("schoonmaakniveau").value) + "</a>";
    }

    var rst = new ResultsetTable({ sql: sql,
                                   ID : "cadschtable",
                                   keyColumn: "alg_ruimte_key",
                                   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: "opp", datatype: "float"}));
    rst.addColumn(new Column({caption: "Vloerafwerking", content: "vloerafwerking"}));
    rst.addColumn(new Column({caption: "Schoonmaakprogramma", content: refDoc}));

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