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

     File:               cnt_edit_contract.asp
     Description:        Toevoegen of bewerken van een contract
     Parameters:         cnt_key              Contract key
     Context:
     Note:

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="cnt_flexkenmerk.inc" -->
<!-- #include file="cnt.inc" -->
<!-- #include file="../Shared/calendar.inc"-->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/kostenplaatsselector.inc" -->
<!-- #include file="../Shared/kostensoortselector.inc" -->
<!-- #include file="../Shared/bedrijfselector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="../Shared/contactpersoonselector.inc" -->
<!-- #include file="../Shared/dienstselector.inc" -->

<%
FCLTHeader.Requires({plugins:["jQuery"],
                     js: ["../cnt/cnt_edit_contract.js"]})

var cnt_key = getQParamInt("cnt_key");
var cnt_disc_key = getQParamInt("srtdisc", -1);
var copy = (getQParamInt("cnt_copy", 0) == 1);

var transitParam = "&cnt_key="+cnt_key;
var cnt_copy_key = -1;
if (copy)
{
  cnt_copy_key = cnt_key;
  cnt_key = -1;
  transitParam = "&cnt_key="+cnt_copy_key+"&cnt_copy=1";
}
if (cnt_key > -1)
{
  var cnt_info = cnt.cnt_contract_info(cnt_key); // nog heel beperkt
  var this_cnt = cnt.func_enabled_contract(cnt_key, cnt_info); // Wat heb ik zoal aan rechten op dit contract?

  user.auth_required_or_abort(this_cnt.canChange);

  if (!cnt_info.locked_user_key || cnt_info.locked_user_key == user_key)
  {
    cnt.lock(cnt_key);
    cnt_info.locked_user_key = user_key;
  }
}
else // nieuw contract of copy
{
  if (copy)
  {
    var cnt_info = cnt.cnt_contract_info(cnt_copy_key);
    var this_cnt = cnt.func_enabled_contract(cnt_copy_key, cnt_info);
    user.auth_required_or_abort(this_cnt.canCopy);
    cnt_info.cnt_key = -1;
    cnt_info.nummer_intern = null;
    cnt_info.contract_status = null;
    cnt_info.contract_status_str = null;
    cnt_disc_key = getQParamInt("srtdisc", -1);
  }
  else
  {
    var cnt_info = {contract_status: S("cnt_contract_approval") == 1 ? 2 : 0};

    if (S("cnt_contract_approval") == 1)
    { // Als het approval mechanisme actief is mag ik met WEB_CNTUSE rechten ook een contract aanmaken.
      var autfunction = ["WEB_CNTUSE", "WEB_CNTMAN"];
      var authparams = user.checkAutorisation(autfunction);
    }
    else
    {
      var autfunction = "WEB_CNTMAN";
      var authparams = user.checkAutorisation(autfunction);
    }

    var authparamsUSE = user.checkAutorisation("WEB_CNTUSE", true) || {PRSreadlevel: 9, PRSwritelevel: 9};
    var haveCNTMSUrights = user.checkAutorisation("WEB_CNTMSU", true) != null; // Pas op: disciplineloos dus niet in cresult!

    var canMANread = authparams.PRSreadlevel < 9;
    var canUSEread = authparamsUSE.PRSreadlevel < 9;
    var canMANwrite = authparams.PRSwritelevel < 9;
    var canUSEwrite = authparamsUSE.PRSwritelevel < 9;
    var this_cnt = {canChangeKosten: true,
                    canChangeAlg: true,
                    isAbonnement: false,
                    // Volgende 4 worden voor de flex gebruikt
                    canMANread  : canMANread,
                    canUSEread  : canUSEread,
                    canMANwrite : canMANwrite,
                    canUSEwrite : canUSEwrite,
                    canInactivateAuto:    (canUSEread || canMANread)
                                       && haveCNTMSUrights
                                       && (    (S("cnt_inactivate_mode") & 1) == 0
                                           || ((S("cnt_inactivate_mode") & 1) == 1 && canUSEwrite))
    };
  }

  var sql = "SELECT dp.cnt_srtcontract_type"
          + "     , dp.cnt_disc_params_factuurschema"
          + "     , dp.cnt_disc_params_fin"
          + "     , dp.cnt_disc_params_binding"
          + "     , dp.cnt_disc_params_leverancier"
          + "     , dp.cnt_disc_params_uitvoerende"
          + "     , dp.cnt_disc_params_huurder"
          + "     , dp.cnt_disc_params_opties"
          + "     , dp.cnt_disc_params_ksverplicht"
          + "     , " +  lcl.xsqla('cs.ins_discipline_omschrijving','cs.ins_discipline_key')
          + "     , (SELECT prs_kostensoort_oms || '-' || " + lcl.xsqla('prs_kostensoort_opmerking', 'prs_kostensoort_key')
          + "         FROM prs_kostensoort"
          + "        WHERE prs_kostensoort_key = cs.prs_kostensoort_key) kostensoort_naam"
          + " FROM cnt_disc_params dp,"
          + "      cnt_discipline cs"
          + " WHERE dp.cnt_ins_discipline_key = " + cnt_disc_key
          + "   AND cs.ins_discipline_key =  " + cnt_disc_key;
  var oRs = Oracle.Execute( sql );

  cnt_info.srtcontract_type = oRs("cnt_srtcontract_type").value;
  cnt_info.discipline_omschrijving = oRs("ins_discipline_omschrijving").value;
  cnt_info.discipline_key = cnt_disc_key;
  cnt_info.hasfactuurschema = oRs("cnt_disc_params_factuurschema").value == 1;
  cnt_info.toon_fin_info = oRs("cnt_disc_params_fin").value == 1;
  cnt_info.kostensoort_naam = oRs("kostensoort_naam").value;
  cnt_info.discipline_binding = oRs("cnt_disc_params_binding").value;
  cnt_info.discipline_leverancier = oRs("cnt_disc_params_leverancier").Value;
  cnt_info.discipline_uitvoerende = oRs("cnt_disc_params_uitvoerende").Value;
  cnt_info.discipline_huurder = oRs("cnt_disc_params_huurder").Value;
  cnt_info.magAutomatischVerlengen = (oRs("cnt_disc_params_opties").Value & 1) == 1;
  cnt_info.discipline_ksverplicht = (oRs("cnt_disc_params_ksverplicht").Value & 1) == 1;

  oRs.close();
}

%>
<html>
  <head>
<%  FCLTHeader.Generate() %>
    <script type="text/javascript">

<% if (copy) { %>
      function make_attachments_readonly()
      {
        $("input[type=button][isbijlage=1]", "td.flexvalue").attr({readonly: true, disabled: true }).addClass("btn_disabled"); // Make attachment buttons readonly and disabled when copying contract
      }
<% } %>

      $(function()
      {
        $('textarea').autogrow();
        FcltMgr.resized(window)
        onChangeVerlengen();
<%if (copy) { %>
        make_attachments_readonly();
<%} %>
      });

      async function cnt_submit()
      {
          document.activeElement.blur(); // trigger laatste onChanges
          if (!await validateForm("u2"))
              return false;

          $("#cnt_prolongation_period").attr("disabled", false);
          $.post($("form[name=u2]")[0].action, $("[name=u2]").serialize(), FcltCallbackAndThenAlways(cnt_submitCallback), "json");
      }

      function cnt_submitCallback(json)
      {
          if (json.success)
          {
              FcltMgr.closeDetail(window, json);
          }
          else
          {
              iface.button.enable("btn_submit");
          }
      }

      function cnt_cancel()
      {
          FcltMgr.closeDetail(window, { cancel: true } );
      }

      // Meestal unlocken we gewoon in showmode die er achteraan komt
      // maar soms wordt het tabblad daarvoor al gesloten. Dan komen
      // we hier langs.
      function onCloseHot()
      {
         var data = { cnt_key: <%=cnt_key%> };
          <% protectRequest.dataToken("data"); %>
          jQuery.ajaxSetup({async: false}); // Anders faalt o.a. bij IE9 de $.post bij afsluiten
          $.post("cnt_unlock.asp",
                 data,
                 FcltCallback,
                 "json");
      }

      function cnt_verlengschema()
      {
        var url = "../cnt/cnt_verlengschema.asp";
        FcltMgr.openModalDetail( "cnt_verlengschema.asp?cnt_key=<%=cnt_key%>&einddatum=" + $("#flddatetot").val()
                               , L("lcl_cnt_prolongation_define")
                               , { width:500, height: 360
                                 , callback: function(data)
                                              {
                                                $("#cnt_prolongation_period").attr("disabled", (data.rowcount > 0));
                                                $("#cnt_prolongation_period").val(data.termijn);
                                              }
                                 });
      }

    </script>

  </head>
  <body class="editmode">
  <% SUBFRAME_START(); %>
<%
    var buttons = [];
    if (!cnt_info.locked_user_key || cnt_info.locked_user_key == user_key)
      buttons.push({title: L("lcl_submit"), action:"cnt_submit()", icon: "fa-fclt-save", singlepress: true, id: "btn_submit" });
    buttons.push({title: L("lcl_cancel"), action:"cnt_cancel()", icon: "fa-fclt-cancel" });

    IFRAMER_HEADER(L("lcl_cnt_frame_algemeen"), buttons);
      if (cnt_info.locked_user_key && cnt_info.locked_user_key != user_key)
      {
        var other = new Perslid(cnt_info.locked_user_key);
%>
        <script type="text/javascript">
          $(function()
          {
            FcltMgr.closeDetail(window, {cancel: true});
          });
        </script>
<%      Response.End;
      }
      if (cnt_info.contract_status == 1)
      {
        SIMPLE_BLOCK_START();
%>      <div class="cnt_inactive"><%=L("lcl_cnt_is_inactive")%></div><%
        SIMPLE_BLOCK_END();
      }
%>
    <script type="text/javascript">
      function checkTextarea(field, klen)
      {
          var value = field.value;
          var valid = value == "" || value.length <= klen;
          validateField(field, valid, L("lcl_cnt_text_toolong1")+klen+ L("lcl_cnt_text_toolong2"));
          return valid;
      }
    </script>
    <form name="u2"
          action="cnt_edit_contract_save.asp?srtdisc=<%=cnt_info.discipline_key%><%=transitParam%>"
          method="post"
          target="hidFrameSubmit"
          onSubmit="cnt_submit();">
<%
        BLOCK_START("cntInfo", L("lcl_cnt_general_info"), {icon: "fa-user-tag"});
        // Het interne contractnr is automatisch&readonly indien S("cnt_internalnr_readonly")
        RWFIELDTR("cnt_cntnrint",  "fld",           L("lcl_cnt_intern_nr"),  cnt_info.nummer_intern, {maxlength: 30, readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg ||S("cnt_internalnr_readonly"), suppressEmpty: true});
        if (!copy)
            ROFIELDTR ("fldshort",                      L("lcl_cnt_versie"),     cnt_info.versie, {suppressEmpty: true, readonly: !this_cnt.canChangeAlg});
        //  CONN#16529/CONN#17562: versienummer wordt via splitsing bepaald, is niet te editen.
        ROFIELDTR("fld",                            L("lcl_cnt_srttype"),    cnt_info.discipline_omschrijving, {readonly: !this_cnt.canChangeAlg});
        RWFIELDTR("cnt_cntomst",  "fld",            L("lcl_cnt_descr"),      cnt_info.omschrijving, {required: true, maxlength: 50, readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg});
        RWFIELDTR("cnt_cntnr",  "fld",              L("lcl_cnt_contractnr"), cnt_info.nummer, {maxlength: 30, readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg});
        // Mantel contracten mogen niet zelf onder een ander contract vallen.
        // Bij mantel contracten selectbox met mantel contracten niet tonen.
        if (cnt_info.srtcontract_type != 6)
        { // Geen Mantel/Master contract. Dan kan selectbox getoond worden.
          sql_mantels = "SELECT cnt_contract_key"
                      + "     , cnt_contract_nummer_intern || DECODE (cnt_contract_versie, NULL, '', '.' || cnt_contract_versie) || ' - ' || cnt_contract_omschrijving"
                      + "  FROM cnt_v_aanwezigcontract c"
                      + "     , cnt_disc_params dp"
                      + "     , cnt_discipline d"
                      + " WHERE dp.cnt_srtcontract_type = 6"  // mastercontracts
                      + "   AND c.ins_discipline_key = dp.cnt_ins_discipline_key"
                      + "   AND d.ins_discipline_key = dp.cnt_ins_discipline_key"
                      + "   AND d.ins_discipline_verwijder IS NULL"
                      + "   AND (   d.ins_discipline_key IN"
                      + "               (SELECT ins_discipline_key"
                      + "                  FROM fac_v_webgebruiker g"
                      + "                     , fac_functie f"
                      + "                 WHERE g.fac_functie_key = f.fac_functie_key"
                      + "                   AND f.fac_functie_code = 'WEB_CNTMAN'"
                      + "                   AND (g.fac_gebruiker_alg_level_read < 9 AND g.fac_gebruiker_prs_level_read < 9)" // prs en alg read rechten
                      + "                   AND g.prs_perslid_key = " + user_key + ")"
                      + "        OR c.prs_perslid_key_beh = " + user_key + ")"
                      + " ORDER BY fac.safe_to_number (cnt_contract_nummer_intern), cnt_contract_nummer_intern, cnt_contract_versie";

          FCLTselector("cnt_macntkey", sql_mantels,
                           { label: L("lcl_cnt_mantel"),
                             initKey: cnt_info.mantel_key,
                             emptyOption: "",
                             readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg,
                             suppressEmpty: true
                          });
        }
        RWTEXTAREATR("cnt_cntdoc", "fldtxt", L("lcl_cnt_document"), cnt_info.document, {readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg});
        FCLTafdelingselector("cnt_owner",
                             "cnt_owner",
                            { departmentKey: cnt_info.afdeling_key_eig,
                              autlevel: authparams && authparams.PRSwritelevel,
                              label: L("lcl_cnt_owner"),
                              required: true,
                              readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg
                            });
        FCLTpersoonselector("cnt_owner_prs", // requestor
                            "sgCnt_owner_prs",
                           { perslidKey: cnt_info.perslid_key_eig,
                             /* bewust geen afhankelijkheid van cnt_owner meer */
                             /* bewust geen filtercode,wat maakt ons het uit? */
                             autlevel: authparams && authparams.PRSwritelevel,
                             label: L("lcl_cnt_contact_eig"),
                             required: S("cnt_contract_requestor_required"),
                             moreinfo: false,  /* PF: omdat de showmode die heeft, en het label erg lang is*/
                             readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg
                          });
        FCLTpersoonselector("cnt_manager", // beheerder
                            "sgcnt_manager",
                           { perslidKey: cnt_info.perslid_key_beh,
                             autlevel: authparams && authparams.PRSwritelevel,
                             label: L("lcl_cnt_manager"),
                             filtercode: "CNTB",
                             required: true,
                             readonly: (cnt_key > -1 && !this_cnt.canMANwrite) || !this_cnt.canChangeAlg,
                             moreinfo: false  /* PF: omdat de showmode die heeft, en het label erg lang is*/
                          });

        var cntopm_ro = (cnt_info.isAbonnement ? !this_cnt.canVerlengen : cnt_info.isAbonnement); // zelfde voorwaarde als het veld Verlengen.
        RWTEXTAREATR("cnt_cntopm", "fldtxt", L("lcl_remark"), cnt_info.opmerking, {html: "onChange='checkTextarea(this, 4000)'", readonly: cntopm_ro, suppressEmpty: true});
        BLOCK_END();

        BLOCK_START("cntData" , L("lcl_cnt_dates"), {icon: "fa-bell-school"});
        ROFIELDTR("fld", L("lcl_cnt_status"), cnt_info.contract_status_str);
        FCLTcalendar( "flddatevan",
                    { label  : L("lcl_cnt_date_start"),
                      datum  : cnt_info.looptijd_van,
                      volgnr: 1,
                      required: true,
                      readonly: (S("cntuse_can_edit_datum") ? !this_cnt.canUSEread : (cnt_info.isAbonnement || !this_cnt.canChangeAlg) )
                    });
        FCLTcalendar( "flddatetot",
                    { label  : L("lcl_cnt_date_end"),
                      datum  : cnt_info.looptijd_tot,
                      volgnr: 2,
                      required: true,
                      readonly: (S("cntuse_can_edit_datum") ? !this_cnt.canUSEread : (cnt_info.isAbonnement || !this_cnt.canChangeAlg) )
                    });
        if (this_cnt.canInactivateAuto)
        {
          RWCHECKBOXTR("cnt_auto_close", "fldautoclose", L("lcl_cnt_auto_close"), cnt_info.inactiveren);
        }
        sql_termijnen = "SELECT t.cnt_termijn_key"
                           + ", "+lcl.xsqla('t.cnt_termijn_omschrijving', 't.cnt_termijn_key')
                           + " FROM cnt_termijn t"
                           + " ORDER BY t.cnt_termijn_volgnummer";
        FCLTselector("cnt_cancel_period", sql_termijnen,
                     { label: L("lcl_cnt_cancel_period"),
                       initKey: cnt_info.opzegtermijn,
                       required: true,
                       emptyOption: "",
                       readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg
                     });
        FCLTselector("cnt_rappel_period", sql_termijnen,
                     { label: L("lcl_cnt_rappel_period"),
                       initKey: cnt_info.rappeltermijn,
                       required: true,
                       emptyOption: "",
                       readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg
                     });
        // Heb ik rechten om verlengen aan te passen. Alleen bij bestaande contracten
        if ((cnt_key > -1 && cnt_info.isAbonnement) || cnt_info.magAutomatischVerlengen)
        { // verlenging:  &1 = verlenging nee/ja
          //              &2 = keuze definitief (zie #23924)
          //              &4 = automatsch verlengen
          sql_verlengen = "SELECT " + (((cnt_info.verlenging & 2) == 2) ? "2" : "0") + ", " + safe.qL("lcl_No")  + ", 3 FROM DUAL"
                        + ( cnt_info.isAbonnement
                          ? " UNION SELECT -1, " + safe.qL("lcl_unknown") + ", 1 FROM DUAL"
                          + " UNION SELECT " + (((cnt_info.verlenging & 2) == 2) ? "3" : "1") + ", " + safe.qL("lcl_Yes") + ", 2 FROM DUAL"
                          : ""
                          )
                        + ( cnt_info.magAutomatischVerlengen
                          ? " UNION SELECT 5, " + safe.qL("lcl_cnt_prolongation_auto") + ", 4 FROM DUAL"
                          : ""
                          )
                        + " ORDER BY 3";
          FCLTselector("cntverlengen", sql_verlengen,
                       { label: L("lcl_cnt_verlengen"),
                         initKey: cnt_info.verlenging,
                         readonly: !(cnt_info.magAutomatischVerlengen || this_cnt.canVerlengen), // Als (cnt_verlenging & 2 == 2) dan is canVerlengen false.
                         onChange: "onChangeVerlengen()"
                       });

          if (cnt_info.magAutomatischVerlengen)
          {
            FCLTselector("cnt_prolongation_period", sql_termijnen,
                         { label: L("lcl_cnt_prolongation_period"),
                           initKey: cnt_info.verlengtermijn,
                           required: true,
                           disable: this_cnt.hasVerlengschema,
                           action: { onclick: 'cnt_verlengschema()'
                                   , title: L("lcl_cnt_prolongation_define_oms")
                                   , icon: "fa-fclt-edit"
                                   },
                           emptyOption: "",
                           readonly: this_cnt.isAbonnement || !this_cnt.canChangeAlg || cnt_info.hasVerlengschema
                         });
          }
        }
        BLOCK_END();

        BLOCK_START("cntBedrijf" , L("lcl_cnt_effecter"), {icon: "fa-handshake"});

        // Algemeen/Generic, Leverancier/Supplier, Mantel/Master, Onderhoud/maintenance of Ondersteuning/Support contracttype
        // Één van de twee, persoon of bedrijf, is verplicht maar niet beide. Dat dwingt een trigger wel af.
        if (cnt_info.discipline_binding & 1) // Show company if selected
        {
          FCLTbedrijfselector("cnt_bdrkey",
                              "sgCompany",
                              { companyKey: cnt_info.bedrijf_key,
                                label: L("lcl_cnt_company"),
                                // De vinkjes leverancier, uitvoerende en huurder bij contractsoort geven aan dat alleen bedrijven die leverancier, uitvoerende en/of huurder zijn,
                                // contractpartij kunnen zijn van een contract van die contractsoort.
                                // Als bij contractsoort de vinkjes leverancier, uitvoerende en huurder alle drie NIET zijn aangevinkt, dan betekent dit "In elk geval contractant".
                                // Of de bedrijven dan leverancier, uitvoerende en/of huurder zijn doet dan niet ter zake.
                                filtercode: "k" + (cnt_info.discipline_leverancier? "L" : "") + (cnt_info.discipline_uitvoerende? "U" : "") + (cnt_info.discipline_huurder? "H" : ""),
                                moreinfo: true,
                                required: !(cnt_info.discipline_binding & 2),
                                emptyOption: "",
                                onChange: "onChangeCompany",
                                readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg
                              });

          FCLTcontactpersoonselector("cnt_contprs",
                                     "sgCntPersUitv",
                                     { contactpersoonKey: cnt_info.contactpersoon_key,
                                       label: L("lcl_cnt_contact_prs"),
                                       urlAdd: [{urlParam: "uitv_key", field: "cnt_bdrkey"}],
                                       moreinfo: true,
                                       readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg,
                                       suppressEmpty: true
                                     });

          FCLTdienstselector("dienst","dienst",
                             { label: L("lcl_prs_companies_dienst"),
                               dienstKey : cnt_info.prs_dienst_key,
                               whenEmpty: L("lcl_select_dienst"),
                               readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg,
                               suppressEmpty: true
                             });
        }

        if (cnt_info.discipline_binding & 2) // Show person if selected
          FCLTpersoonselector("cnt_prskey", // requestor
                              "sgPerson",
                              { perslidKey: cnt_info.perslid_key,
                                /* bewust geen afhankelijkheid van cnt_owner meer */
                                /* bewust geen filtercode, wat maakt ons het uit? */
                                autlevel: authparams && authparams.PRSwritelevel,
                                label: L("lcl_person"),
                                required: !(cnt_info.discipline_binding & 1),
                                moreinfo: true,
                                emptyOption: "",
                                onChange: "onChangePerson",
                                readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg,
                                suppressEmpty: true
                              });
        BLOCK_END();

        if (cnt_info.toon_fin_info) {
          BLOCK_START("cntFindata" , L("lcl_cnt_fin_data"), {icon: "fa-coins"});
          FCLTkostenplaatsselector("prs_kstplkey",
                                   "prs_kstplkey",
                                   user_key,
                                   { label: L("lcl_cnt_kostenplaats"),
                                     kostenplaatsKey: cnt_info.prs_kostenplaats_key,
                                     required: true,
                                     filtercode: (S("cnt_all_kostenplaats") == 1? "A" : null),
                                     readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg
                                   });

          if (cnt_info.isAbonnement || !this_cnt.canChangeAlg)
              ROFIELDTR ("fldkp",
                         L("lcl_cnt_kostensoort"),
                         cnt_info.kostensoort_naam,
                         { suppressEmpty: true,
                           required: cnt_info.discipline_ksverplicht }
                        );
          else
          {
              ROFIELDTR ("fldkp", L("lcl_cnt_kostensoort_standaard"), cnt_info.kostensoort_naam, {suppressEmpty: true});
              if (S("cnt_enable_kostensoort") != 0)
                  FCLTkostensoortselector("prs_kstsrtkey",
                                          "prs_kstsrtkey",
                                          { kostensoortKey: cnt_info.prs_kostensoort_key,
                                            label: L("lcl_cnt_kostensoort_specifiek"),
                                            filtercode: "CNT",
                                            refkey: cnt_key,
                                            required: cnt_info.discipline_ksverplicht
                                          });
          }

          if (cnt_info.hasfactuurschema)
          {
              ROFIELDTR ("fld", L("lcl_cnt_period_sum"), L("lcl_cnt_see_factuurschema"));
          }
          else
          {
              RWFIELDTR("cnt_termkstn", "fldshort float",  L("lcl_cnt_period_sum") + " " + L("lcl_valutasign"), safe.curreditable(cnt_info.termijnkosten), {readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg, suppressEmpty: true});
              FCLTselector("cnt_term_period", sql_termijnen,
                           { label: L("lcl_cnt_period_period"),
                             initKey: cnt_info.termijntermijn,
                             required: false,
                             emptyOption: "",
                             readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg,
                             suppressEmpty: true
                           });
          }
          // TODO: berekend jaarbedrag hiertussen??
          RWFIELDTR("cnt_cntkstn",  "fldshort float",  L("lcl_cnt_contract_sum") + " " + L("lcl_valutasign"),
                                      safe.curreditable(cnt_info.kosten),
                                      { readonly: !this_cnt.canChangeKosten || !this_cnt.canChangeAlg, suppressEmpty: true} );
          RWFIELDTR("cnt_uurloon",  "fldshort float",      L("lcl_hour_rate") + " " + L("lcl_valutasign"), safe.curreditable(cnt_info.uurloon), {readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg, suppressEmpty: true});
          RWFIELDTR("cnt_korting",  "fldshort float",      L("lcl_cnt_discount"), cnt_info.korting, {datatype:"float", readonly: cnt_info.isAbonnement || !this_cnt.canChangeAlg, suppressEmpty: true});
          BLOCK_END();
        }

        generateFlexKenmerkCode ({ cnt_key      : copy ? cnt_copy_key : cnt_key,
                                   disc_key_arr : [cnt_info.discipline_key],
                                   copy         : copy,
                                   this_cnt     : this_cnt
                                 });
IFACE.FORM_END();
%>
    </form>
    <% SUBFRAME_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
