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

<%
DOCTYPE_Disable = true;
%>

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

<%
// Build an article list
//var autfunction = getQParam("autfunction", ""); // Check of user rechten heeft op meegegeven artikelen
var bedrijf_key = getQParamInt("bedrijf_key", -1); // Uitvoerende key
var cnt_key = getQParamInt("cnt_key", -1); // Contract key
var mld_key = getQParamInt("mld_key", -1); // Melding key
var moreinfo = getQParamInt("mld_key", 0) == 1; // Moet moreinfo getoond worden
var typeopdr_contract = getQParamInt("typeopdr_contract"); // mld_typeopdr_contract

var authparamsORDBOF = user.checkAutorisation("WEB_ORDBOF", true);
var authparamsMLDBOF = user.checkAutorisation("WEB_MLDBOF", true);
var authparamsMLDBO3 = user.checkAutorisation("WEB_MLDBO3", true);

if (authparamsORDBOF || authparamsMLDBOF || authparamsMLDBO3)
{
  var sql = " SELECT cnt.cnt_contract_key cnt_key"
          + ", '* ' || cnt.cnt_contract_nummer_intern"
            + " || CASE WHEN cnt.cnt_contract_versie IS NOT NULL THEN '.'||cnt.cnt_contract_versie  END"
            + " || '-' || cnt.cnt_contract_omschrijving cnt_name"
          + ", cnt.cnt_prs_bedrijf_key bedrijf_key"
          + ", (SELECT b.prs_bedrijf_naam naam FROM prs_bedrijf b WHERE b.prs_bedrijf_key = cnt.cnt_prs_bedrijf_key) bedrijf_naam"
          + ", 1"
          + ", cnt.cnt_contract_nummer_intern"
          + ", cnt.cnt_contract_versie"
          + " FROM cnt_v_aanwezigcontract cnt"
          + ", cnt_contract_object co"
          + ", mld_melding_object mo "
          + " WHERE cnt.cnt_contract_key = co.cnt_contract_key"
          + " AND co.cnt_ins_deel_key = mo.ins_deel_key"
          + " AND cnt.cnt_contract_status = 0" // actief
          + " AND mo.mld_melding_key = " + mld_key
          + (bedrijf_key > 0
            ? " AND cnt_prs_bedrijf_key = " + bedrijf_key
            : "")
          + " UNION"
          + " SELECT cnt.cnt_contract_key cnt_key"
          + ", cnt.cnt_contract_nummer_intern"
            + " || CASE WHEN cnt.cnt_contract_versie IS NOT NULL THEN '.'||cnt.cnt_contract_versie  END"
            + " || '-' || cnt.cnt_contract_omschrijving cnt_name"
          + ", cnt.cnt_prs_bedrijf_key bedrijf_key"
          + ", (SELECT b.prs_bedrijf_naam naam FROM prs_bedrijf b WHERE b.prs_bedrijf_key = cnt.cnt_prs_bedrijf_key) bedrijf_naam"
          + ", 2"
          + ", cnt.cnt_contract_nummer_intern"
          + ", cnt.cnt_contract_versie"
          + " FROM cnt_v_aanwezigcontract cnt"
          + ", cnt_contract_plaats cp"
          + ", mld_melding me"
          + ", cnt_disc_params cpa "
          + " WHERE cnt.cnt_contract_key = cp.cnt_contract_key"
          + " AND cnt.ins_discipline_key = cpa.cnt_ins_discipline_key"
          + " AND cnt.cnt_contract_status = 0" // actief
          + " AND ((cp.cnt_alg_plaats_key = me.mld_alg_locatie_key"
            + " AND cp.cnt_alg_plaats_code = 'L')"
            + " OR (cp.cnt_alg_plaats_key ="
              + " (SELECT alg_gebouw_key FROM alg_v_onroerendgoed og"
              + " WHERE og.alg_onroerendgoed_keys = me.mld_alg_onroerendgoed_keys)"
              + " AND cp.cnt_alg_plaats_code = 'G'))"
          + " AND me.mld_melding_key = " + mld_key
          + (bedrijf_key > 0
            ? " AND cnt_prs_bedrijf_key = " + bedrijf_key
            : "")
          + " ORDER BY 4,6,7 DESC";
}
else
{
  var sql = "";
}

FCLTselector("contract",
             sql,
             { initKey: cnt_key,
               moreinfo: moreinfo,
               extraParamValue: "bedrijf_key, bedrijf_naam",
               onChange: "onChangeContract()",
               emptyOption: "",
               required: typeopdr_contract & 1
             });
%>

