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

<!--#include file="../Shared/common.inc"-->
<!--#include file="../Shared/resultset_table_v2.inc" -->
<!--#include file="./mld.inc" -->
<%
var opdr_uren_key = getQParamInt("opdr_uren_key");
%>
<html>
<%
   FCLTHeader.Generate();
%>

<body id="listbody">
<%

  // Workflow Details for Root call of a workflow sequence
  // Or follow-up calls for this one
 if (opdr_uren_key > -1) {

  // Lijkt me iets voor mld.inc
  sql = "SELECT mld_opdr_uren_datum, prs_perslid_key, mld_opdr_uren_status "
      + " FROM mld_opdr_uren u"
      + " WHERE mld_opdr_uren_key = " + opdr_uren_key;

  oRs = Oracle.Execute(sql);
  var aday = new Date(oRs("mld_opdr_uren_datum").value);
  var medewerker_key = oRs("prs_perslid_key").value;
  var uren_status = oRs("mld_opdr_uren_status").value;

var startofweek = new Date(aday);
startofweek.setDate(startofweek.getDate() - aday.getDay() + 1);
var endofweek = new Date(startofweek);
endofweek.setDate(startofweek.getDate() + 6);

function fnOpdrachtNr(oRs) {
    return oRs("mld_melding_key").value+"/"+oRs("mld_opdr_bedrijfopdr_volgnr").value;
}

  sql = "SELECT u.mld_opdr_uren_key,"
      + "       u.mld_opdr_uren_datum,"
      + "       u.mld_opdr_key,"
      + "       u.mld_opdr_uren_status,"
      + "       u.mld_opdr_uren_besteed, "
      + "       pf.prs_perslid_naam_full melder, "
      + "       m.mld_melding_key,"
      + "       o.mld_opdr_bedrijfopdr_volgnr"
      + " FROM mld_opdr_uren u, mld_opdr o, mld_melding m, prs_v_perslid_fullnames_all pf"
      + " WHERE u.prs_perslid_key = " + medewerker_key
      + "   AND u.mld_opdr_key = o.mld_opdr_key"
      + "   AND o.mld_melding_key = m.mld_melding_key (+)"  // kan evt ook bij contract behoren
      + "   AND m.prs_perslid_key = pf.prs_perslid_key"
      + "   AND mld_opdr_uren_datum BETWEEN "+ startofweek.toSQL() +" AND " +endofweek.toSQL()
      + " ORDER BY 1";


    var buttons = [];
    if (uren_status == 2) // statusafhankelijk
    {
      var addurl = "appl/mld/XX";
      buttons.push({ icon: "plus.png", title: L("lcl_add"), action: "FcltMgr.openDetail('" + addurl + "', '" + L("lcl_add") + "')" });
    }

    var rst = new ResultsetTable({ sql: sql,
                                   title: "",
                                   ID : "opdrurentable",
                                   keyColumn: "mld_opdr_uren_key",
                                   buttons: buttons
                                   });

    rst.addColumn(new Column({caption: L("lcl_mld_date"), content: "mld_opdr_uren_datum", datatype:"date"}));
    rst.addColumn(new Column({caption: "Opdracht", content: fnOpdrachtNr}));
    rst.addColumn(new Column({caption: "Aanvrager", content: "melder"}));
    rst.addColumn(new Column({caption: "Uren", content: "mld_opdr_uren_besteed", datatype: "currency"}));
    rst.addColumn(new Column({caption: "Status", content: "mld_opdr_uren_status"}));

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

