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

     File:               bes_reject.asp
     Description:        Afwijzen van een bestelaanvraag door de de fiatteur. (canApprove)
                         OF: Door de Backoffice (canAccept)
                         Opmerking moet ingevuld worden.
     Parameters:
         bes_key         Bestelaanvraag nummer (key)
         submitting      0 = invoer opmerking, 1 = reject mode
         opmerk          Opmerking
*/ %>

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

<%
FCLTHeader.Requires({ plugins: ["jQuery"] });

var bes_key_arr = getQParamIntArray("bes_key");
var submitting = getQParamInt("submit", 0) == 1;
var opmerk = getFParam("opmerk", "");

var result = {};
var toberejected = 0;
var ingesloten = [];
var hasparentkey = [];
var hasnoparentkey = [];
// Bepaal de bestellingen in de selectie die
// ook echt afgewezen kunnen of mogen worden.
for (var i = 0; i < bes_key_arr.length; i++)
{
  var bes_bestelling = bes.bestelling_info(bes_key_arr[i]); // Globale variabele met alle bes_bestelling informatie
  var bes_disc_info = bes.disc_info(bes_bestelling.dis_key); // alle discipline informatie
  var this_bes = bes.func_enabled_bestelling(bes_bestelling);
  if (this_bes.canApprove || this_bes.canReject) // Als je mag fiatteren mag je ook rejecten
  {
    ingesloten.push(bes_key_arr[i]);
    if (bes_bestelling.parent_key)
      hasparentkey.push(bes_key_arr[i]);
    else
      hasnoparentkey.push(bes_key_arr[i]);
    toberejected++;
  }
}
user.anything_todo_or_abort(toberejected > 0); // We klagen niet over enkele wel en enkele niet
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
      <script type="text/javascript">
        jQuery(document).ready(function()
                               {
                                 $('textarea').resize(function() { FcltMgr.resized(window) });
                                 $('textarea').autogrow();
                               });
        function bes_reject()
        {
          // Standaard checks op verplichte velden, datum formaat, numeriek en float formaat, currency formaat.
          if (!validateForm("rejectform"))
            return false;

          $.post($("form[name=rejectform]")[0].action, $("[name=rejectform]").serialize(), FcltCallbackClose, "json");;
          return true; // disable submit
        }

        function bes_cancel()
        {
          FcltMgr.closeDetail(window, { cancel: true } );
        }
      </script>
  </head>

  <body class="modal" id="besrejectbody">
      <form id="rejectform" name="rejectform" action="bes_reject_save.asp?bes_key=<%=ingesloten.join(",")%>" method="post">
<%
        BLOCK_START("besReject", L("lcl_bes_rejectfollowing") + S("bes_bestelling_prefix") + ingesloten.join(", " + S("bes_bestelling_prefix")));
        RWTEXTAREATR("opmerk", "fldremark required", L("lcl_bes_reject_remark"), "", {html: "rows='8'"});
        BLOCK_END();
        var buttons =  [{ title: L("lcl_reject"), icon: "opslaan.png", action: "bes_reject()", singlepress: true, id: "btn_reject_submit" },
                        { title: L("lcl_cancel"), icon: "undo.png", action: "bes_cancel()" }];
        CreateButtons(buttons);
IFACE.FORM_END();
%>
      </form>
  </body>
</html>
