<%@ language="javascript"%>
<% /*
     $Revision$
     $Id$
*/%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->

<%
var highlight_arr  = getQParamIntArray("highlight", []); // Comma-separated room_key_list (terrains). Optional
var floorKey = getQParamInt("vKey", -1);

var outputmode = getQParamInt("outputmode", 0);
var showall    = getQParamInt("showall", 0) == 1;

var authparams = user.checkAutorisation("WEB_CADCNT");  // en scope enzo dan?

var sql = "";
if (floorKey > 0)
{
    sql = "SELECT c.cnt_contract_nummer_intern,"
        + "       c.cnt_contract_versie,"
        + "       cnt_contract_omschrijving,"
        + "       aog.alg_plaatsaanduiding,"
        + "       cnt_contract_looptijd_tot,"
        + "       c.cnt_contract_key,"
        + "       cp.cnt_alg_plaats_code"
        + "  FROM cnt_contract_plaats cp, cnt_contract c,"
        + "       (SELECT alg_onroerendgoed_keys, alg_type, alg_plaatsaanduiding FROM alg_v_onroerendgoed_gegevens UNION SELECT alg_locatie_key, 'L', alg_locatie_code FROM alg_locatie) aog"
        + " WHERE     cp.cnt_alg_plaats_key = aog.alg_onroerendgoed_keys"
        + "       AND cp.cnt_alg_plaats_code = aog.alg_type"
        + "       AND cp.cnt_contract_key = c.cnt_contract_key"
        + "       AND c.cnt_contract_verwijder IS NULL"
        + "       AND c.cnt_contract_status = 0"
        //+ "       AND c.cnt_contract_looptijd_van <= SYSDATE"
        + "       AND c.cnt_contract_looptijd_tot >= SYSDATE"
        + "       AND (   (    cnt_alg_plaats_code = 'G'"
        + "                AND cnt_alg_plaats_key IN (SELECT alg_gebouw_key"
        + "                                             FROM alg_verdieping"
        + "                                            WHERE alg_verdieping_key = "+floorKey+"))"
        + "            OR (    cnt_alg_plaats_code = 'L'"
        + "                AND cnt_alg_plaats_key IN"
        + "                        (SELECT g.alg_locatie_key"
        + "                           FROM alg_verdieping v, alg_gebouw g"
        + "                          WHERE v.alg_gebouw_key = g.alg_gebouw_key"
        + "                            AND v.alg_verdieping_key = "+floorKey+"))"
        + "            OR (    cnt_alg_plaats_code = 'R'"
        + "                AND cnt_alg_plaats_key IN"
        + "                        (SELECT r.alg_ruimte_key"
        + "                           FROM alg_verdieping v, alg_ruimte r"
        + "                          WHERE v.alg_verdieping_key = r.alg_verdieping_key "
        + ((highlight_arr.length > 0 && highlight_arr.join(",").indexOf("-1") == -1)
          ? "     AND cnt_alg_plaats_code = 'R' AND cnt_alg_plaats_key IN (" + highlight_arr.join(",") + ")"
          : "")
        + "                            AND v.alg_verdieping_key = "+floorKey+"))"
        + "            OR (cnt_alg_plaats_code = 'V' AND cnt_alg_plaats_key = "+floorKey+"))"
        + " ORDER BY 1,2";
}
else
{
  sql = "SELECT * FROM DUAL WHERE 1 = 0";
}

function fncolContractnr(oRs)
{
  var cnt_nr = oRs("cnt_contract_nummer_intern").value;
  if (oRs("cnt_contract_versie").value)
    cnt_nr += "."+oRs("cnt_contract_versie").value;
  return safe.html(cnt_nr);
}
%>

<html>
  <head>
<%  FCLTHeader.Generate({ outputmode: outputmode }); %>
    <script type="text/javascript">
      function onClickContract(row)
      {
        FcltMgr.openDetail("appl/cnt/cnt_contract.asp?urole=fe&cnt_key=" + row.getAttribute("ROWKEY"));
      }
    </script>
  </head>

  <body class="tabpage">
<%  var rst = new ResultsetTable({ keyColumn: "cnt_contract_key",
                               sql: sql,
                               ID: "fgcnttable",
                               outputmode: outputmode,
                               showAll: showall
                             });

    rst.addColumn(new Column({caption: L("lcl_cnt_intern_nr"), content: fncolContractnr}));
    rst.addColumn(new Column({caption: L("lcl_cnt_document"), content: "cnt_contract_omschrijving"}));
    rst.addColumn(new Column({caption: L("cnt_contract_plaats"), content: "alg_plaatsaanduiding"}));
    rst.addColumn(new Column({caption: L("lcl_cnt_date_end"), content: "cnt_contract_looptijd_tot"}));
    //rst.addColumn(new Column({caption: L("x"), content: "cnt_alg_plaats_code"}));

    rst.addAction({action: "onClickContract", caption: L("lcl_edit"), isDefault: true});

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