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

     File:      mld/kpi_detail.asp
*/ %>

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

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

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

var locatie = "Alle";
if (fclt_key > 0)
{
    var sql_l = "SELECT fac_usrdata_code"
              + "  FROM fac_usrtab t"
              + "     , fac_usrdata d"
              + " WHERE t.fac_usrtab_key = d.fac_usrtab_key"
              + "   AND t.fac_usrtab_object = 'USR_KPI INSTELLINGEN'"
              + "   AND d.fac_usrdata_volgnr = " + fclt_key;
    var oRs_l = Oracle.Execute(sql_l);
    if (!oRs_l.eof)
        locatie = oRs_l("fac_usrdata_code").Value;
    oRs_l.Close();
}

if (periode == "")
{
    // Neem de laatste periode als er geen periode is opgegeven.
    var sql_p = "SELECT MAX(TO_DATE(d.fac_usrdata_code, 'yyyymm')) periode"
              + "  FROM fac_usrtab t"
              + "     , fac_usrdata d"
              + " WHERE t.fac_usrtab_key = d.fac_usrtab_key"
              + "   AND t.fac_usrtab_object = 'USR_KPI PERIODE'";
    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 = "proces";
    v_col2 = "onderdeel";
    lbl_header = "KPI: Onderdelen van proces " + proces;
}
else
{
    v_head = onderdeel;
    v_col1 = "onderdeel";
    v_col2 = "proces";
    lbl_header = "KPI: Processen van onderdeel " + onderdeel;
}


%>

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

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

  </head>

  <body id="showbody">
    <div id="show">
      <form name="u2">

<style>
    table {
      border: none;
      width: 100%;
      margin: 0;
      padding: 0;
    }
    td {
      font-family: Verdana;
      font-style: normal;
      font-size: 8pt;
      font-weight: normal;
      color:  #000000;
      text-align: left;
      vertical-align: top;
    }
    span.prim_header {
      font-style:  normal;
      font-size:   18pt;
      float:left;
    }
    td.sec_heading {
      background-color: #eee;
      color: #000;
      font-size: 18pt;
      text-align: left;
      vertical-align: bottom;
      padding: 5px;
    }
    td.avg {
      color: #fff;
      font-size: 2em;
      text-align: center;
      vertical-align: middle;
      width: 100px;
      height: 80px;
    }
    td.score {
      width: 50px;
    }
</style>

    <div class="fcltframeheader">
      <span class="prim_header"><nobr><%=safe.html(lbl_header)%>&nbsp;<span id="iframerextratitle"></span></nobr></span>
    </div>
        <table>
<%
    var sql_h = "SELECT DISTINCT " + v_col2 + " totaalnaam"
              + "     , totaalscore"
              + "     , totaalkleur"
              + "  FROM akza_v_kpi_proc_ond_detail"
              + " WHERE locatie = " + safe.quoted_sql(locatie)
              + "   AND TO_CHAR(periode, '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="sec_heading"><%=safe.html(h_head_naam)%></td>
          </tr>
          <tr>
            <td class="avg" style="background-color: <%=h_head_kleur%>"><%=h_head_score%></td>
            <td>
              <table>
<%
        var sql_s = "SELECT kpi_omschrijving"
                  + "     , kpi_uitleg"
                  + "     , score"
                  + "     , kleur"
                  + "  FROM akza_v_kpi_proc_ond_detail"
                  + " WHERE locatie = " + safe.quoted_sql(locatie)
                  + "   AND TO_CHAR(periode, '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.html(s_uitlg)%>"><%=safe.html(s_omsch)%></td>
                  <td title="<%=safe.html(s_uitlg)%>" class="score"><%=safe.html(s_score)%></td>
                </tr>
<%
            oRs_s.MoveNext();
        }
        oRs_s.Close();
%>
              </table>
            </td>
          </tr>
<%
        oRs_h.MoveNext();
    }
    oRs_h.Close();
%>
        </table>
<%

      var buttons = [{ title: L("lcl_cancel"), action: "doCancel();"}];
      CreateButtons(buttons, { entersubmit: true });
%>
      </form>
    </div>
  </body>
</html>
