<%@ language="javascript"%>
<% /*
     $Revision$
     $Id$

     File:        cust/AANS/rap_alg.asp
     Description: Inhoud van het ALG-tabblad van FG
     Parameters:  floorKey (required)
                  highlight (optional list of room-keys to filter)
     Context:     -
*/%>

<!-- #include file="../../Appl/Shared/common.inc" -->
<!-- #include file="../../Appl/Shared/resultset_table_v2.inc" -->

<%
var floorKey   = getQParamInt("vKey", -1);
var highlight_arr = getQParamIntArray("highlight", []); // Comma-separated room_key_list (terrains). Optional

var outputmode = getQParam("outputmode", 0);
var showall    = getQParam("showall", 0) == 1;

var sql = "";
if (floorKey != -1)
{     
  sql = " SELECT   r.alg_ruimte_key, r.alg_ruimte_aanduiding, sr.alg_srtruimte_omschrijving,"
      + "          hd.vvo, (COALESCE(hd.prs_ruimteafdeling_bezetting,100)/100)*r.alg_ruimte_bruto_vloeropp bvo, r.alg_ruimte_omschrijving,"
      +"           r.alg_ruimte_bruto_vloeropp, hd.prs_ruimteafdeling_bezetting bezetting,"
      + "          (SELECT " + S("prs_dep_string")
      + "             FROM prs_v_afdeling d"
      + "            WHERE d.prs_afdeling_key = hd.prs_afdeling_key) afdeling"
      + "   FROM aans_v_rap_huurdetail hd, "
      + "        alg_v_ruimte_gegevens r, "
      + "        alg_srtruimte sr "
      + "  WHERE hd.alg_ruimte_key(+) = r.alg_ruimte_key"
      + "    AND r.alg_srtruimte_key = sr.alg_srtruimte_key"
      + "    AND r.alg_verdieping_key = " + floorKey
      + (highlight_arr.length > 0 && highlight_arr.join(",").indexOf("-1") == -1
        ? " AND r.alg_ruimte_key IN (" + highlight_arr.join(",") + ")"
        : "")
      + " ORDER BY alg_ruimte_aanduiding, afdeling";
}
else
{ // Er is (nog) geen verdieping bekend
  sql = "SELECT * FROM DUAL WHERE 1 = 0";
}
%>
<html>
  <head>
<%  FCLTHeader.Generate({outputmode: outputmode, root: "../../appl/"}); %>
    <script type="text/javascript">
      function onClickRuimte(row)
      {
        FcltMgr.openDetail("appl/alg/alg_ruimte.asp?key=" + row.getAttribute("ROWKEY"));
      }
    </script>
  </head>

  <body class="tabpage">
<%
    var summaryParams = {selectedopp: 0.00, selectedoppAlt1: 0.00}
    var ruimte_aanduiding_prev = "";

    function fnsummaryCalc(oRs)
    {
      with (summaryParams)
      {
        if (ruimte_aanduiding_prev != oRs("alg_ruimte_aanduiding").value)
           selectedopp = selectedopp + oRs("alg_ruimte_bruto_vloeropp").value;
        ruimte_aanduiding_prev = oRs("alg_ruimte_aanduiding").value;
        selectedoppAlt1 = selectedoppAlt1 + oRs("vvo").value;
      }
      return;
    }

    function fnsummaryShow()
    {
      var status_row = "<label>" + L("lcl_estate_totaal_opp") + "</label> "
                     + "<label>" + L("lcl_estate_ruimte_bruto_vloeropp") + "</label>: " + summaryParams.selectedopp.toFixed(2) + " " + L("lcl_estate_ruimte_opp_m2");
        status_row += ", <label>" + L("lcl_estate_ruimte_opp_alt1") + "</label>: " + summaryParams.selectedoppAlt1.toFixed(2) + " " + L("lcl_estate_ruimte_opp_m2");
      return status_row;
    }

    var rst = new ResultsetTable({ ID : "cadalgtable",
                                   keyColumn: "alg_ruimte_key",
                                   title: L("lcl_space_manage_h"),
                                   sql: sql,
                                   outputmode: outputmode,
                                   showAll: showall,
                                   summaryCalc: fnsummaryCalc,
                                   summaryShow: fnsummaryShow
                                 });

    rst.addColumn(new Column({caption: L("lcl_obj_inf_room"), content: "alg_ruimte_aanduiding"}));
    rst.addColumn(new Column({caption: L("lcl_fg_func_names"), content: "alg_srtruimte_omschrijving"}));
    rst.addColumn(new Column({caption: L("lcl_descr"), content: "alg_ruimte_omschrijving"}));
    rst.addColumn(new Column({caption: L("lcl_department"), content: "afdeling"}));
    rst.addColumn(new Column({caption: L("lcl_procent"), content: "bezetting", datatype: "float"}));
    rst.addColumn(new Column({caption: L("lcl_estate_ruimte_bruto_vloeropp"), content: "bvo", datatype: "float"}));
    rst.addColumn(new Column({caption: L("lcl_estate_ruimte_opp_alt1"), content: "vvo", datatype: "float"}));

    rst.addAction({ action: "onClickRuimte", caption: L("lcl_edit"), isDefault: true } );

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

