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

    File:               bestelling.asp
    Description:        Bekijk/wijzig bestelling (Mobile version)
    Parameters:         bes_key voor bestaande bestelling
                        bes_key=-1 voor nieuwe bestelling, en dan
                            stdm_key
                            ins_key
                            ruimte_key
                            -
                            rest optioneel

    Note:

*/ %>

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

<%
var urole = getQParamSafe("urole", "fe");
var bes_key = getQParamInt("bes_key",-1);
var qrc = getQParamInt("qrc", 0) != 0;

// Mogelijke parameters voor toevoegen only
if (bes_key == -1)
{
  // NIEUWE BESTELLING
  var subject = L("lcl_mld_new_bestelling");
}

if (bes_key > -1)
{
  // BESTAANDE BESTELLING
  var subject = L("lcl_bes_bestelling") + " " + S("bes_bestelling_prefix") + bes_key;
  var bes_bestelling = bes.bestelling_info(bes_key); // Globale variabele met alle bes_bestelling informatie
  var bes_disc_info  = bes.disc_info(bes_bestelling.dis_key); // alle discipline informatie
  var bes_opdracht   = bes.bestelopdracht(bes_bestelling);
  var this_bes = bes.func_enabled_bestelling(bes_bestelling); // Wat heb ik zoal aan rechten op deze specifieke bestelling
  user.auth_required_or_abort(this_bes.canReadAny);
}

%>
<html>
  <head>
<%
    FCLTMHeader.Generate({title:  subject }); %>
    <script type="text/javascript">
      function bes_approve()
      {
        var best_nr = "<%=S("bes_bestelling_prefix") + bes_key%>";
        if (confirm(L("lcl_bes_approve").format("<%=bes_key%>")))
        {
          var data = { bes_key: <%=bes_key%>
                     };
          <% protectRequest.dataToken("data"); %>
          $.post("<%=rooturl%>/appl/bes/bes_approve.asp"
                , data
                , McltCallbackAndThenAlways(bes_approve_callback)
                , "json");
        }
      }
      function bes_reject()
      {
        var opmerk = prompt(L("lcl_bes_reject_remark"), "");
        if (!opmerk)
            return;
        var best_nr = "<%=S("bes_bestelling_prefix") + bes_key%>";
        if (confirm(L("lcl_bes_reject_1").format(best_nr)))
        {
          var murl = "?bes_key=<%=bes_key%>&submit=1"
          var data = { bes_key: <%=bes_key%>
                     , opmerk: opmerk
                     };
          <% protectRequest.dataToken("data"); %>
          $.post("<%=rooturl%>/appl/bes/bes_reject_save.asp" + murl
                , data
                , McltCallbackAndThenAlways(bes_approve_callback)
                , "json");
        }
      }
      function bes_approve_callback()
      {
        //window.location.href = "fiat_list.asp"; // Als je terug bent in fiat_list en doet dan "terug" kom je in de zojuist gefiatteerde bestelling.
        // Het fiatteren van een bestelling is aangeroepen vanuit fiat_list.
        // Dus 1 stap terug in history om daar weer te komen.
        window.history.go(-1);
      }
    </script>
  </head>
  <body>
<%
// resultsettable functies voor bestelitems.
  function fncolLink(oRs)
  {
    return "../pda/bes_bestelling_item.asp?ins_key=" + oRs("bes_bestelling_item_key").Value;
  };
  function fncolGroup(oRs)
  {
    return safe.html(oRs("bes_srtdeel_nr").value);
  };
  function fncolHeader(oRs)
  {
    return safe.html(oRs("bes_bestelling_item_aantal").value);
  };
  function fncolDetail(oRs)
  {
    return safe.html(oRs("bes_srtdeel_omschrijving").value);
  };
  function fnAside(oRs)
  {
    return safe.html(oRs("bes_bestelling_item_aantalontv").value);
  }

  var sql = "SELECT I.bes_bestelling_item_key"
          + "     , I.bes_bestelling_item_aantal"
          + "     , I.bes_bestelling_item_aantalontv"
          + "     , I.bes_bestelling_item_prijs"
          + "     , S.bes_srtdeel_nr"
          + "     , S.bes_srtdeel_omschrijving"
          + "  FROM bes_bestelling_item I"
          + "     , bes_srtdeel S"
          + " WHERE I.bes_srtdeel_key = S.bes_srtdeel_key"
          + "   AND I.bes_bestelling_key = " + bes_key;
  var resultset_params = { sql: sql
                         , keyColumn: "bes_bestelling_item_key"
                      // , linkColumn: fncolLink
                      // , groupColumn: fncolGroup
                         , headerColumn: fncolHeader
                         , detailColumn: fncolDetail
                         , asideColumn: fnAside
                      // , subheaderColumn: "bes_bestelling_item_prijs"
                         , ID: "bestelitemtable"
                         , showAll: true
                         , noSearch: true
                         };


// Einde resultsettable functies voor bestelitems.

      PAGE_START({id: "page-1-"+bes_key});
        HEADER({ title: subject
               , back:!qrc
               , home: !qrc
               });
        CONTENT_START();
// Altijd forcesave omdat we geen doublecheck aankunnen
%>
      <form name="best" id="best" action="../bes/bes_edit_bestelling_save.asp" method="post">
        <input type="hidden" name="bes_key" value="<%=bes_key%>">
        <input type="hidden" name="forcesave" id="forcesave" value="0">
        <input type="hidden" name="parent_key" id="parent_key" value="-1">
        <input type="hidden" name="urole" value="<%=bes_key > 0? "bo" : "fe"%>">
<%
          BLOCK_START({collapsed: true, title: L("lcl_bes_RFO")});
            ROFIELD("fld", L("lcl_bes_discipline"), bes_disc_info.discipline_omschrijving);
            ROFIELD("fld", L("lcl_bes_RFO_status"), bes_bestelling.rfoStatusText);
            ROFIELD("fld", L("lcl_date_time")     , toDateTimeString(bes_bestelling.rfoDate));
            ROFIELD("fld", L("lcl_bes_orders")    , bes_opdracht.txt[0], {suppressEmpty: true});
            //
            ROFIELD("fld", L("lcl_bes_deli_date") , toDateString(bes_bestelling.rfoDeliverydate));
            ROFIELD("fld", L("lcl_bes_del_place"), bes_bestelling.mld_adres_naam);
            ROFIELD("fld", L("lcl_bes_del_room") , bes_bestelling.afleverruimte);
            //
            BLOCK_START({collapsed: false, title: L("lcl_bes_delivery")});
              ROFIELD("fld", L("lcl_bes_opmerking"), bes_bestelling.lev_opm, {suppressEmpty: true} );
            BLOCK_END();
            //
              generateFlexKenmerkCode ({ urole: urole
                                       , bes_key: bes_bestelling.bes_key
                                       , disc_key: bes_bestelling.dis_key
                                       , kenmerktype: "B"
                                       , mobile: true
                                       , reado: true
                                       });
          BLOCK_END();
          //
          BLOCK_START({collapsed: false, title: L("lcl_bes_geselecteerd")});
            var rst = new ResultsetTable(resultset_params);
            var cnt = rst.processResultset();
          BLOCK_END();
          //
          //
          CONTROLGROUP_START()
            //if ((this_bes.canChange || bes_key == -1) && !this_bes.canApprove)
            //{
            //  BUTTON((bes_key>-1 ? L("lcl_submit") : L("lcl_newsubmit")), {click: "bes_submit()", icon: "refresh"});
            //}
            if (bes_bestelling.fac_activiteit_key == -1)
            {
              if (this_bes.canApprove)
              {
                BUTTON(L("lcl_approve"), {click: "bes_approve()", icon: "fa-check"});
                BUTTON(L("lcl_reject"),  {click: "bes_reject()",  icon: "fa-times"});
              }
            }
            if (bes_key > -1)
            {
              if (this_bes.canAccept)
              {
                BUTTON(L("lcl_bes_accept"), {click: "bes_accept()", icon: "fa-check"});
              }
              if (this_bes.canClose)
              {
                BUTTON(L("lcl_close"), {click: "bes_close()", icon: "fa-flag-checkered"});
              }
              trackinglines = mobile.hastrackingpage('bestelling', bes_key);
              if (trackinglines>0)
              {
                BUTTON(L("lcl_history"), {linkid: "#bes-2-"+bes_key, icon: "fa-list"});
              }
            }
          CONTROLGROUP_END()
        IFACE.FORM_END();
%>
      </form>
<%
        CONTENT_END();
      FOOTER();
      PAGE_END()
      if (bes_key > -1)
      {
        if (trackinglines>0)
        {
          PAGE_START({id: "bes-2-"+bes_key, dialog: true})
            mobile.trackingpage('bestelling', bes_key, S("bes_bestelling_prefix") + bes_key);
          PAGE_END();
        }
      }
PDA_PAGE_END(); %>
	</body>
</html>
<% ASPPAGE_END(); %>
