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

    File:               mld_opdr_uitvoerenden.asp
    Description:        (Modal)dialoog om uitvoerenden aan een opdracht te kunnen koppelen
    Globalen:
        opdr_key        Opdracht key
    Context:
    Note:
*/
%>

<!-- #include file="../shared/common.inc" -->
<!-- #include file="../Shared/uitvoerendeselector.inc" -->
<!-- #include file="../Shared/contactpersoonselector.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="mld.inc" -->

<%
FCLTHeader.Requires({ plugins: ["jQuery"],
                      js: ["../mld/mld_opdr_uitvoerenden.js", "num2curr.js"]
                    })

var opdr_key = getQParamInt("opdr_key");
var mld_key = getQParamInt("mld_key");
var cnt_key = getQParamInt("cnt_key");
var dienst_key = getQParamInt("dienst_key");
var readonly = getQParamInt("readonly", 0) == 1;
var autlevel = getQParamInt("autlevel");
var srtdiscbes = getQParamInt("srtdiscbes") == 1;
var loc_key = getQParamInt("loc_key");
var onrgoed_key = getQParamInt("onrgoed_key");
var bld_key = getQParamInt("bld_key");
var disckey = getQParamInt("disckey");
var lutype = srtdiscbes? "L" : "U";
var opdrtype = getQParamInt("opdrtype");

var sql = "SELECT mld_typeopdr_contract"
        + "  FROM mld_typeopdr mto"
        + " WHERE mto.mld_typeopdr_key = " + opdrtype;
var oRs = Oracle.Execute(sql);
var typeopdr_contract = oRs("mld_typeopdr_contract").Value;

if (!readonly && opdr_key > 0)
{
  this_opdr = mld.func_enabled_opdracht(opdr_key); // wat mag ik zoal op deze opdracht
  readonly = !this_opdr.canChange;
}
%>

<html>
  <head>
<%  FCLTHeader.Generate() %>
    <script type="text/javascript">
      var uitvkeystr = FcltMgr.dialogArguments().uitvkeystr;
      var uitvcpersstr = FcltMgr.dialogArguments().uitvcpersstr;
      var uitvcntstr = FcltMgr.dialogArguments().uitvcntstr;
      var mld_ordermaterial_fac_usrtab_key = <%=S("mld_ordermaterial_fac_usrtab_key")%>;
      var srtdiscbes = <%=srtdiscbes? 1 : 0%> == 1;
      var lutype = "<%=lutype%>";
      var loc_key = <%=loc_key%>;
      var mld_key = <%=mld_key%>;
      var typeopdr_contract = <%=typeopdr_contract%>;
    </script>
  </head>

  <body class="modal" id="mod_mlduitv">
    <form name="u2" method="post">

<%    if (!readonly)
      { %>
        <div id="uitvoerendenselect" style="display: <%=readonly? "none" : "block"%>">
<%        BLOCK_START("mld_selobj", srtdiscbes? L("lcl_mld_opdr_leveranciers_select") : L("lcl_mld_opdr_uitvoerenden_select")) %>
          <tr>
            <td style="width:45%" align="center" valign="top">
              <div id='req_uitvPossible' class='flduitvPossible'>
                <table class="test">
                  <tr>
                    <td align="left">
                      <label class="details"><%=(srtdiscbes? L("lcl_mld_opdr_leveranciers_available") : L("lcl_mld_opdr_uitvoerenden_available")) + ":"%></label><br><br>
                    </td>
                  </tr>
                  <tr>
                    <td align="left">
                      <label class="details"><%=(srtdiscbes? L("lcl_bes_Supplier") : L("lcl_mld_opdr_bedrijf")) + ":"%></label>
                    </td>
                  </tr>
                  <tr>
                    <td align="left">
                      <input type="hidden" name="dienst" id="dienst" value="<%=dienst_key%>">
<%                    // Uitvoerende/Leverancier
                      FCLTuitvoerendeselector("uitvPossible",
                                               "sgUitv",
                                               { uitvoerendekey: -1,
                                                 autlevel: autlevel,
                                                 whenEmpty: srtdiscbes? L("lcl_select_bedrijf") : null,
                                                 locatiekey: loc_key,
                                                 onrgoedkey: onrgoed_key,
                                                 gebouwkey: bld_key,
                                                 disciplinekey: disckey,
                                                 lutype: lutype, // leverancier of uitvoerende
                                                 externonly: true,
                                                 urlAdd: [{urlParam: "dienst", field: "dienst"}],
                                                 onChange: "onChangeUitv",
                                                 readonly: readonly
                                               });
%>
                    </td>
                  </tr>
                  <tr>
                    <td align="left">
                      <label class="details"><%=L("lcl_contact_pers") + ":"%></label>
                    </td>
                  </tr>
                  <tr>
                    <td align="left">
<%                    // Contactpersoon
                      FCLTcontactpersoonselector("contactpers",
                                                  "sgCntPersUitv",
                                                  { contactpersoonKey: -1,
                                                    suppressEmpty: true,
                                                    locatiekey: loc_key,
                                                    filtercode: "U",
                                                    urlAdd: [{urlParam: "uitv_key", field: "uitvPossible"}],
                                                    readonly: readonly
                                                  }); %>
                    </td>
                  </tr>
<%
                  // Veld mld_typeopdr_contract met codering
                  //  &0 = geen contract te kiezen bij opdrachten van dit type
                  //  &1 = contract verplicht bij opdrachten van dit type
                  //  &2 = wel contract te kiezen bij opdrachten van dit type (=default)
                  if (typeopdr_contract & 2)
                  { %>
                    <tr>
                      <td align="left">
                        <label class="details"><%=L("lcl_contract") + ":"%></label>
                      </td>
                    </tr>
                    <tr>
                      <td align="left">
<%                      // Contactpersoon
                        var sql_contract = " SELECT cnt.cnt_contract_key cnt_key"
                                         + "      , '* ' || cnt.cnt_contract_nummer_intern || '-' || 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"
                                         + "   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 IN (0, 1)"
                                         + "    AND mo.mld_melding_key = " + mld_key
                                         + " UNION"
                                         + " SELECT cnt.cnt_contract_key cnt_key"
                                         + "      , cnt.cnt_contract_nummer_intern || '-' || 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"
                                         + "   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 cnt.cnt_contract_status IN (0, 1)"
                                         + "    AND me.mld_melding_key = " + mld_key
                                         + " ORDER BY 4,2";

                        FCLTselector("contract",
                                     sql_contract,
                                     { initKey: cnt_key,
                                       emptyOption: "",
                                       extraParamValue: "bedrijf_key, bedrijf_naam",
                                       onChange: "onChangeContract()",
                                       required: typeopdr_contract & 1,
                                       readonly: readonly
                                     });
%>
                      </td>
                    </tr>
<%                } %>
                  <tr>
                    <td align="left">
                    <br><div class="opdrfooter"><%=(typeopdr_contract & 2? L("lcl_mld_opdr_invullen") : L("lcl_mld_opdr_invullen_cp")) + ":"%></div>
                    </td>
                  </tr>
                </table>
              </div>
            </td>
            <td>
              <div class="mv r" onclick="moveRight()"><%=L("lcl_mld_opdr_add")%></div>
              <div class="mv l" onclick="moveLeft()"><%=L("lcl_mld_opdr_remove")%></div>
            </td>
            <td style="width:45%">
              <label class="details"><%=(srtdiscbes? L("lcl_mld_opdr_leveranciers_selected") : L("lcl_mld_opdr_uitvoerenden_selected")) + ':'%></label><br>
<%            sql = "";
              // Wordt via load methode vervangen omdat uitvkeystr clientside beschikbaar is.
              // Uitvkeystr is niet via url meegezonden. Maximum lengte van url is 2083 karakters (maximum path lengte is 2048 karakters). Dit kan anders problemen/foutmelding geven
              FCLTselector("uitvExist",
                           sql,
                           { startmulti: true,
                             size: 10
                           });
%>
              <script type="text/javascript">
                jQuery(document).ready(function()
                   {
                     $("#uitvExist").load("loadUitvoerendenOptions.asp",
                                          {
                                            uitvkeystr: uitvkeystr,
                                            uitvcpersstr: uitvcpersstr,
                                            uitvcntstr: uitvcntstr,
                                            mld_key: mld_key,
                                            filter: "E",
                                            lutype: lutype // leverancier of uitvoerende
                                          });
                   });
              </script>
            </td>
          </tr>
<%        BLOCK_END()
          var buttons = [{title: L("lcl_submit"), icon: "opslaan.png", action: "submit()"},
                         {title: L("lcl_cancel"), icon: "undo.png", action: "FcltMgr.closeDetail(window, { cancel: true })"}];
          CreateButtons(buttons);
%>
        </div>
<%    } IFACE.FORM_END();
%>
    </form>
  </body>
</html>
