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

     File:        CAD/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", []);
var outputmode = getQParamInt("outputmode" ,0);
var showall    = getQParamInt("showall" ,0) == 1;

var sql = "";
if (floorKey != -1)
{
  sql = " SELECT alg_ruimte_key, alg_ruimte_nr, alg_srtruimte_omschrijving, prs_ruimteafdeling_bezetting, "
      + "        alg_ruimte_bruto_vloeropp, alg_ruimte_omschrijving, alg_ruimte_opp_alt1, alg_ruimte_opp_alt2, "
      + "        werkplekken, prs_afdeling_omschrijving "
      + "   FROM aaen_v_ruimte_bezetting "
      + "  WHERE alg_verdieping_key = " + floorKey
      + (highlight_arr.length
        ? " AND alg_ruimte_key IN (" + highlight_arr.join(",") + ")"
        : "")
      + " ORDER BY alg_ruimte_nr, prs_afdeling_omschrijving";
}
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 onClickRuimteAlternatief(room_key)
      {
        sl = parent.parent.document.getElementById("rooms");
        if( sl.selectedIndex == -1 || sl.options[sl.selectedIndex].value != room_key )
        {
          for (i = 0; i < sl.length; i++)
          {
            if (sl.options[i].value == room_key)
            {
              sl.selectedIndex = i;
              parent.parent.OnRoomChanged(sl);
            }
          }
        }
      }
      function onClickRuimte(row)
      {
        FcltMgr.openDetail("appl/ALG/alg_ruimte.asp?key=" + row.getAttribute("ROWKEY"), "<%=L("lcl_estate_ruimte_title")%>");
      }
    </script>
  </head>

  <body class="tabpage">
<%
    var summaryParams = {selectedopp: 0, selectedoppAlt1: 0, selectedoppAlt2: 0, selectedWP: 0}

    function fnsummaryCalc(oRs)
    {
      with (summaryParams)
      {
        selectedopp = selectedopp + (oRs("alg_ruimte_bruto_vloeropp").value != null? oRs("alg_ruimte_bruto_vloeropp").value : 0);
        selectedWP = selectedWP + (oRs("werkplekken").value != null? oRs("werkplekken").value : 0);
        selectedoppAlt1 = selectedoppAlt1 + (oRs("alg_ruimte_opp_alt1").value != null? oRs("alg_ruimte_opp_alt1").value : 0);
        selectedoppAlt2 = selectedoppAlt2 + (oRs("alg_ruimte_opp_alt2").value != null? oRs("alg_ruimte_opp_alt2").value : 0);
      }
      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");
      if (S("fg_contourlayers_alt1") != "" && S("fg_labellayers_alt1") != "")
        status_row += ", <label>" + L("lcl_estate_ruimte_opp_alt1") + "</label>: " + summaryParams.selectedoppAlt1.toFixed(2) + " " + L("lcl_estate_ruimte_opp_m2");
      if (S("fg_contourlayers_alt2") != "" && S("fg_labellayers_alt2") != "")
        status_row += ", <label>" + L("lcl_estate_ruimte_opp_alt2") + "</label>: " + summaryParams.selectedoppAlt2.toFixed(2) + " " + L("lcl_estate_ruimte_opp_m2");
      status_row += ", <label>" + "Aantal werkplekken" + "</label>: " + summaryParams.selectedWP + " " ;
      return status_row;
    }

    var lastValue = null;
    function showRoomDesc(oRs)
    { // leek leuk om herhalingen te onderdrukken, maar sorteren maakt het waardeloos
      if (false && outputmode == 0 && safe.htmlattr(oRs("alg_ruimte_nr").value) == lastValue)
      var result = null;
      else
        var result = safe.htmlattr(oRs("alg_ruimte_nr").value);
      lastValue = result;
      return result;
    }

    function fnOpp(oRs)
    {
      return (oRs("alg_ruimte_bruto_vloeropp").value != null? "" + oRs("alg_ruimte_bruto_vloeropp").value.toFixed(2) : "-");
    }

    function fnOppAlt1(oRs)
    {
      return (oRs("alg_ruimte_opp_alt1").value != null? "" + oRs("alg_ruimte_opp_alt1").value.toFixed(2) : "-");
    }

    function fnOppAlt2(oRs)
    {
      return (oRs("alg_ruimte_opp_alt2").value != null? "" + oRs("alg_ruimte_opp_alt2").value.toFixed(2) : "-");
    }

    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: showRoomDesc}));
    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: "prs_afdeling_omschrijving"}));
    rst.addColumn(new Column({caption: "Bezetting", content: "prs_ruimteafdeling_bezetting", datatype: "integer"}));
    rst.addColumn(new Column({caption: L("lcl_estate_ruimte_bruto_vloeropp"), content: fnOpp, datatype: "float"}));
    if (S("fg_contourlayers_alt1") != "" && S("fg_labellayers_alt1") != "")
      rst.addColumn(new Column({caption: L("lcl_estate_ruimte_opp_alt1"), content: fnOppAlt1, datatype: "float"}));
    if (S("fg_contourlayers_alt2") != "" && S("fg_labellayers_alt2") != "")
      rst.addColumn(new Column({caption: L("lcl_estate_ruimte_opp_alt2"), content: fnOppAlt2, datatype: "float"}));

    rst.addColumn(new Column({caption: 'Aantal werkplekken', content: "werkplekken", datatype: "integer"}));
    rst.addAction({ action: "onClickRuimte", caption: L("lcl_edit"), isDefault: true } );
    var cnt = rst.processResultset();
%>
  </body>
</html>

