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

     File:          ins_pricechange.asp
     Description:   Invoer prijswijziging (%) van de taken in het periodieke taken overzicht.
     Parameters:    Geen.
     Context:       Vanuit /mgt/ins_srtcontrole.asp of /mjb/mjb_search_list.asp.

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<%
// Dit scherm wordt aangeroepen vanuit het periodieke taken overzicht of vanuit het mjob overzicht om de kosten van de taken aan te passen (in procenten).
// Bij periodiek taken wordt de kosten in de ins_srtcontrole tabel aangepast, bij mjob taken worden de kosten in de ins_srtcontroledl_xcp tabel aangepast.
// Om periodieke taken te kunnen wijzigen heb je WEB_INSMGT rechten nodig.
// OM mjob (xcp) taken te kunnen wijzigen heb je (WEB_INSUSE of ik ben objectbeheerder) + WEB_CTRUSE + WEB_INSMAN rechten nodig.

// Heb ik de juiste rechten bij periodieke taken (PT).
var authparams_PT = user.checkAutorisation("WEB_INSMGT", true);
var hasWrite_PT = authparams_PT && authparams_PT.ALGwritelevel < 9 && authparams_PT.PRSwritelevel < 9;

// Heb ik de juiste rechten bij MJOB.
// Ben ik een objectbeheerder van een object?
var sql = "SELECT ins_deel_key"
        + "  FROM ins_deel d"
        + " WHERE d.prs_perslid_key_beh = " + user_key;
var oRs = Oracle.Execute(sql);
var objectBeheerder = !oRs.eof;
oRs.Close();

var authparamsINSUSE = user.checkAutorisation("WEB_INSUSE", true);
var authparamsCTRUSE = user.checkAutorisation("WEB_CTRUSE", true);
var authparamsINSMAN = user.checkAutorisation("WEB_INSMAN", true);
var hasWriteINSUSE = authparamsINSUSE && authparamsINSUSE.ALGwritelevel < 9 && authparamsINSUSE.PRSwritelevel < 9;
var hasWriteCTRUSE = authparamsCTRUSE && authparamsCTRUSE.ALGwritelevel < 9 && authparamsCTRUSE.PRSwritelevel < 9;
var hasWriteINSMAN = authparamsINSMAN && authparamsINSMAN.ALGwritelevel < 9 && authparamsINSMAN.PRSwritelevel < 9;
var hasWrite_MJOB = (hasWriteINSUSE || (S("ins_can_edit_own_objects") && objectBeheerder)) && hasWriteCTRUSE && hasWriteINSMAN

user.anything_todo_or_abort(hasWrite_PT || hasWrite_MJOB);

// Er moeten wel actieve kosten velden aanwezig zijn.
var ins_xcp_active_cost = S("ins_xcp_active_cost");
user.auth_required_or_abort(ins_xcp_active_cost > 0 && ins_xcp_active_cost < 16);

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

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

        async function ins_submit()
        {
          if (!await validateForm("u2"))
            return false;

          data = {};
          if (ins_xcp_active_cost & 1)
            data.costs = $("#costs").val();
          if (ins_xcp_active_cost & 2)
            data.costs2 = $("#costs2").val();
          if (ins_xcp_active_cost & 4)
            data.costs3 = $("#costs3").val();
          if (ins_xcp_active_cost & 8)
             data.material = $("#material").val();
          data.adjust_xcp = ($("#adjust_xcp").is(":checked")? 1 : 0);
          FcltMgr.closeDetail(window, data );
        }

        function checkPrice(fieldnr)
        {
          if (fieldnr < 4)
            fieldname = "costs" + (fieldnr > 1? fieldnr : "")
          else
            fieldname = "material"

          var valid_pricechange = false;
          var pricechange = $("#" + fieldname).val();
          if (!(pricechange == null || pricechange == "" || typeof pricechange == "undefined"))
          {
            pricechange = parseFloat($("#" + fieldname).val().replace(',', '.'));
            valid_pricechange = !isNaN(pricechange);
            if (valid_pricechange)
              $("#" + fieldname).val(num2currEditable(pricechange));
          }
        }

        $(function()
        {
          $("#pricechange").focus();
        });

      </script>
  </head>

  <body class="fclt-modal" id="mod_inspricechange">
  <% MODAL_START(); %>
    <form id="pricechangeform" name="pricechangeform" action="javascript:ins_submit()" method="post">
<%
      MODAL_BLOCK_START("insPriceChange", L("lcl_mjb_factor"), { "icon": "fa-money-bill-transfer" });

      if (ins_xcp_active_cost & 1)
        RWFIELDTR("costs",
                  "fldshort",
                  L("ins_srtcontrole_kosten") + " (%)",
                  "",
                  { datatype: "float",
                    html: "onBlur='checkPrice(1)'" })
      if (ins_xcp_active_cost & 2)
        RWFIELDTR("costs2",
                  "fldshort",
                  L("ins_srtcontrole_kosten2") + " (%)",
                  "",
                  { datatype: "float",
                    html: "onBlur='checkPrice(2)'" })
      if (ins_xcp_active_cost & 4)
        RWFIELDTR("costs3",
                  "fldshort",
                  L("ins_srtcontrole_kosten3") + " (%)",
                  "",
                  { datatype: "float",
                    html: "onBlur='checkPrice(3)'" })
      if (ins_xcp_active_cost & 8)
        RWFIELDTR("material",
                  "fldshort",
                  L("ins_srtcontrole_materiaal") + " (%)",
                  "",
                  { datatype: "float",
                    html: "onBlur='checkPrice(4)'" })
%>        <tr><td colspan="2">
            <% CHECKBOX("fldcheck", "adjust_xcp"); %>
            <label for="adjust_xcp"><%=L("lcl_srtcontrole_adjust_xcp")%></label>
          </td></tr>
<%

      MODAL_BLOCK_END();

      buttons = [];
      buttons.push({title: L("lcl_submit"), icon: "fa-fclt-save", action:"ins_submit()" });
      buttons.push({title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "ins_cancel()" });
      SIMPLE_BLOCK_START();
        CreateButtons(buttons);
      SIMPLE_BLOCK_END();
      IFACE.FORM_END();
%>
    </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
