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

     File:               fin_reject.asp
     Description:        Afwijzen van een factuur. Reden van afwijzen moet ingevuld worden.
     Parameters:
         fin_key         fin_factuur_keys (required) format n or "n,n,...n" (!!!)

     Context:
     Note:

*/
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="fin.inc" -->
<%

FCLTHeader.Requires({ plugins: ["suggest", "jQuery", "kenmerk"] });

var fin_key_arr = getQParamIntArray("fin_key");

user.anything_todo_or_abort(S("fin_enable_afwijzen") == 1);

var result = { };
var toberejected = 0;
var ingesloten = [];
// Bepaal de facturen in de selectie die
// ook echt afgewezen kunnen of mogen worden.
for (var i = 0; i < fin_key_arr.length; i++)
{
  var this_fin = fin.func_enabled_factuur(fin_key_arr[i]);
  if (this_fin.canReject)
  {
    ingesloten.push (fin_key_arr[i]);
    toberejected++;
  }
}
user.anything_todo_or_abort(toberejected > 0); // enkele wel en enkele niet klagen we niet over

if (fin_key_arr.length == 1)
{
  fin.factuur_info
}
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>

    <script type="text/javascript">
      $(function()
      {
        $('textarea').resize(function () { FcltMgr.resized(window) } );
        $('textarea').autogrow();
      });

      async function fin_reject()
      { // Standaard checks op verplichte velden, datum formaat, numeriek en float formaat, currency formaat.
        if (!await validateForm("rejectform"))
          return false;

        $.post( $("form[name=rejectform]")[0].action,
                $("[name=rejectform]").serialize(),
                FcltCallbackAndThenAlways(fin_reject_close),
                "json"
              );

        return true; // disable button
      }

      function fin_reject_close(data)
      {
        FcltMgr.closeDetail( window,
                             { key: data.fin_key,
                               warning: data.warning,
                               success: data.success
                             });
      }

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

  <body class="fclt-modal" id="mod_rejectbody">
    <% MODAL_START(); %>
      <form id="rejectform" name="rejectform" action="fin_reject_save.asp" method="post">
        <input type="hidden" id="fin_key" name="fin_key" value="<%=ingesloten.join(",")%>">
<%      MODAL_BLOCK_START("finReject", (ingesloten.length == 1? L("lcl_fin_invoice") + " " + ingesloten[0] : L("lcl_fin_invoices") + ": " + ingesloten.join(", ")), { icon: "fa-times" });
        // Reden afwijzing
        RWTEXTAREATR("opmerk",
                     "fldtxt required",
                     L("lcl_fin_remark_reject"),
                     "",
                     {html: "rows='8'"});
        MODAL_BLOCK_END();

        var buttons =  [ {title: L("lcl_reject"), icon: "fa-fclt-save", action: "fin_reject()", singlepress: true, id: "btn_reject_submit", importance: 1 },
                         {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "fin_cancel()", importance: 3 }];
        SIMPLE_BLOCK_START();
        CreateButtons(buttons);
        SIMPLE_BLOCK_END();
        IFACE.FORM_END(); %>
      </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
