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

     File:          mld_behandelverloop.asp
     Beschrijving:  Toont het chronlogisch behandelverloop van een melding obv Behandelteams-toekenningen
                    inclusief de absolute (in minuten) en relatieve periode (in procenten)

*/%>
<!--#include file="../Shared/common.inc"-->
<!--#include file="../Shared/status.inc" -->
<!--#include file="../Shared/resultset_table_v2.inc" -->
<!--#include file="mld.inc" -->
<%
var mld_key    = getQParamInt("mld_key");
var outputmode = getQParamInt("outputmode", 0);

// checkautorisatie
var this_mld = mld.func_enabled_melding(mld_key);
user.auth_required_or_abort(this_mld.canFOread || this_mld.canBOread || this_mld.canMIread);  // FE-only mag niet
%>
<html>
  <head>
<%  FCLTHeader.Generate({ outputmode: outputmode }); %>
  </head>
  <body class="listmode">
<%
  // de tijdlijn van een melding die van behandelteam naar behandelteam wordt doorgestuurd (sequentieel)
  var sql = "SELECT datum"
          + "     , event"
          + "     , eventtext"
          + "     , behandelteam"
          + "     , minuten"
          + "     , percentage"
          + "  FROM mld_v_behandelverloop"
          + " WHERE mld_melding_key = " + mld_key
          + "   AND event <> 'NOW'"
          + " ORDER BY datum, eventkey";

  var buttons = [{ icon: "fa-fclt-refresh", title: L("lcl_refresh"), action: "FcltMgr.reload()" }];

  function formatDaysHoursMinutes(minutesDuration)
  {
    var totalSeconds = Math.floor(minutesDuration * 60);
    var days = Math.floor(totalSeconds / (60 * 60 * 24));
    var hours = Math.floor((totalSeconds % (60 * 60 * 24)) / (60 * 60));
    var minutes = Math.floor((totalSeconds % (60 * 60)) / 60);

    return "{0}d {1}h {2}m".format(days, hours, ("0"+minutes).slice(-2));
  }

  function formatInterval (oRs)
  {
    var retval ="";
    if (oRs("minuten").Value != null)
      if (outputmode == 0 || outputmode == 1)  // scherm of print
        retval = formatDaysHoursMinutes(oRs("minuten").Value);
      else
        retval = safe.html(oRs("minuten").Value);

    return retval;
  }

  function formatEventText (oRs)
  {
    // We weten: voor deze versie 2024.3 werd behandelteam (fac_tracking_subject_refkey) niet geregistreerd.
    // Om dan toch iig visueel de info te tonen wordt dan de oude trackingtekst (fac_tracking_oms) getoond.
    var retval = "";
    if (oRs("event").value == "MLDBHG" && oRs("behandelteam").Value == null)
        retval = oRs("eventtext").value;
    else
        retval = status.getsrtnotificatietext (oRs("event").value);

    return safe.html(retval);
  }

  // Voortgangsindicator dankbaar geleend van mld_list
  function fnfnProgress(oRs)
  {
    var retval = "";
    if (oRs("percentage").Value != null)
    {
      // de periode bij de FO krijgt een alt1 styling
      if (outputmode == 0)
          retval =  "<div class='mldProgress"+((oRs("event").value == "MLDNEW" || oRs("event").value == "MLDBWD") ? " alt1": "")+"' style='width:100%'>"
                  + "  <div class='mldBar' data-perc='" + oRs("percentage").Value + "' style='width:" + oRs("percentage").Value +"%'></div>"
                  + "</div>";
      else
        retval = oRs("percentage").Value;
    }
    return retval;
  }

  var sum_minuten = 0;
  function fnsummaryCalc(oRs)
  {
    if (oRs("minuten").Value)
      sum_minuten += oRs("minuten").Value;
    return;
  }

  function fnsummaryShow()
  {
    if (sum_minuten)
      return L("lcl_Total") + " " + formatDaysHoursMinutes(sum_minuten);
  }


  var rst = new ResultsetTable({ sql:sql,
                                  ID: "mldverlooptable",
                                  outputmode: outputmode,
                                  showAll: true,
                                  buttons: buttons,
                                  summaryCalc: fnsummaryCalc,
                                  summaryShow: fnsummaryShow
                                });

  rst.addColumn(new Column({caption: L("lcl_date_time"), content: "datum", datatype: "datetime"}));
  rst.addColumn(new Column({caption: L("lcl_event"), content: formatEventText, datatype: "string" }));
  rst.addColumn(new Column({caption: L("mld_processing_group"), content: "behandelteam", datatype: "string" }));
  rst.addColumn(new Column({caption: L("lcl_interval"), content: formatInterval}));
  rst.addColumn(new Column({caption: L("lcl_ratio"), content: fnfnProgress, colName: "fnfnProgress", colText: L("lcl_mld_progress"), align: "center"}));

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