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

     File:      kpi/kpi_detail.asp
*/ %>

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

<%
FCLTHeader.Requires({ plugins:["jQuery"] });

/***** Get webform parameters *****/
var loc_key   = getQParamInt("fclt_key", -1);
var periode   = getQParam("periode", "");
var proces    = getQParam("fclt_f_kpi_definitie_categorie1", "");
var onderdeel = getQParam("fclt_f_kpi_definitie_categorie2", "");
var barselect = getQParam("_titel_", "");

if (loc_key > -1) {
    var sql_l = " SELECT " + S("alg_loc_string")
              + "   FROM alg_locatie l"
              + "  WHERE alg_locatie_key = " + loc_key;
    var oRs = Oracle.Execute(sql_l);
    var locatie = oRs(0).Value;
}
else
    var locatie = L("lcl_all");

if (periode == "") {
    // Neem de laatste periode als er geen periode is opgegeven.
    var sql_p = "SELECT TO_CHAR(MAX(kpi_score_datum), 'yyyymm') periode"
              + "  FROM kpi_score";
    var oRs_p = Oracle.Execute(sql_p);
    user.anything_todo_or_abort(oRs_p.eof);
    periode = oRs_p("periode").Value;
    oRs_p.Close();
}

if (proces != "")
{
    v_head = proces;
    v_col1 = "kpi_definitie_categorie1";
    v_col2 = "kpi_definitie_categorie2";
    lbl_header = L("lcl_kpi_cat2_van_cat1").format(proces);
}
else
{
    v_head = onderdeel;
    v_col1 = "kpi_definitie_categorie2";
    v_col2 = "kpi_definitie_categorie1";
    lbl_header = L("lcl_kpi_cat1_van_cat2").format(onderdeel);
}

%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>

    <script type="text/javascript">
      function doCancel()
      {
          FcltMgr.closeDetail(window, { cancel: true } );
      }
    </script>
  </head>

  <body class="showmode">
    <div class="fcltframeheader kpiprim_header"><%=safe.html(lbl_header)%></div>
    <table class="kpidetails">
<%
    var sql_h = "SELECT DISTINCT " + v_col2 + " totaalnaam"
              + "     , totaalscore"
              + "     , totaalkleur"
                  + "  FROM kpi_v_cat1_cat2_detail"
                  + " WHERE alg_locatie_key = " + loc_key // en -1 betekent all
                  + "   AND TO_CHAR(kpi_score_datum, 'yyyymm') = " + safe.quoted_sql(periode)
              + "   AND " + v_col1 + " = " + safe.quoted_sql(v_head)
              + " ORDER BY totaalscore";

var oRs_h = Oracle.Execute(sql_h);
while (!oRs_h.eof)
{
    h_head_naam  = oRs_h("totaalnaam").Value;
    h_head_score = oRs_h("totaalscore").Value;
    h_head_kleur = oRs_h("totaalkleur").Value;
%>
      <tr>
        <td colspan="2" class="kpisec_heading"><%=safe.html(h_head_naam)%></td>
      </tr>
      <tr>
        <td class="kpiavg" style="background-color: <%=safe.htmlattr(h_head_kleur)%>"><%=h_head_score%></td>
        <td>
          <table>
<%
    var sql_s = "SELECT kpi_omschrijving"
              + "     , kpi_uitleg"
              + "     , score"
              + "     , kleur"
              + "  FROM kpi_v_cat1_cat2_detail"
              + " WHERE alg_locatie_key = " + loc_key // en -1 betekent all
              + "   AND TO_CHAR(kpi_score_datum, 'yyyymm') = " + safe.quoted_sql(periode)
              + "   AND " + v_col1 + " = " + safe.quoted_sql(v_head)
              + "   AND " + v_col2 + " = " + safe.quoted_sql(h_head_naam)
              + " ORDER BY score";

    var oRs_s = Oracle.Execute(sql_s);
    while (!oRs_s.eof)
    {
        s_omsch = oRs_s("kpi_omschrijving").Value;
        s_uitlg = oRs_s("kpi_uitleg").Value;
        s_score = oRs_s("score").Value;
        s_kleur = oRs_s("kleur").Value;
%>
            <tr>
              <td title="<%=safe.htmlattr(s_uitlg)%>" class="kpioms"><%=safe.html(s_omsch)%></td>
              <td title="<%=safe.htmlattr(s_uitlg)%>" class="kpiscore"><%=safe.html(s_score)%></td>
            </tr>
<%
        oRs_s.MoveNext();
    }
    oRs_s.Close();
%>
          </table>
        </td>
      </tr>
<%
    oRs_h.MoveNext();
}
oRs_h.Close();
%>
    </table>
  </body>
</html>
<% ASPPAGE_END(); %>
