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

    File:               pda/factuur.asp
    Description:        Invoices data (Mobile version)
    Parameters:

    Status:             opzetje

    Note:               Since Mobile is limited to actual actions, only invoices that need approval by me are shown

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../fin/fin.inc" -->
<!-- #include file="../fin/fin_flexkenmerk.inc" -->
<!-- #include file="./resultset_table.inc" -->
<!-- #include file="./mobile.inc" -->
<!-- #include file="./iface.inc" -->
<%
  var fin_key = getQParamInt("fin_key");
  var qrc = getQParamInt("qrc", 0) != 0;

var this_fin = fin.func_enabled_factuur(fin_key); // Wat heb ik zoal aan rechten
var fin_factuur = this_fin.factuur_info;
var ref_info = this_fin.referentieinfo;

var subject = L("lcl_fin_invoice") + " " + fin_key;
%>
<html>
<head>
<% FCLTMHeader.Generate({title: subject}); %>
    <script type="text/javascript">
        // draft, kopie van bes
      function fin_approve()
      {
        if (confirm('<%=L("lcl_fin_approve_factuur").format(fin_key)%>'))
        {
          var data = { fin_key: <%=fin_key%>
                     };
          <% protectRequest.dataToken("data"); %>
          $.post("../fin/fin_approve.asp?a=1"
                , data
                , McltCallbackAndThenAlways(fin_approve_callback)
                , "json");
        }
      }
      function fin_reject()
      {
        var opmerk = prompt('<% =L("lcl_fin_remark")%>', "");
        if (!opmerk)
            return;
        if (confirm('<%=L("lcl_fin_reject_factuur").format(fin_key)%>'))
        {
          var murl = "?fin_key=<%=fin_key%>&r=1&submit=1"
          var data = { fin_key: <%=fin_key%>
                     , opmerk: opmerk
                     };
          <% protectRequest.dataToken("data"); %>
          $.post("../fin/fin_approve.asp" + murl
                , data
                , McltCallbackAndThenAlways(fin_approve_callback)
                , "json");
        }
      }
      function fin_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>
<%
    PAGE_START();
    HEADER ({title: subject, back:!qrc, home:!qrc});
    CONTENT_START();

      var nurl="";
      switch (ref_info.ref_type)
      {
        case "B":
        {
          nurl = "../pda/bestelling.asp?bes_key=" + ref_info.bestelling_key;
          break;
        }
        case "C":
        {
          nurl = "../pda/contract.asp?cnt_key=" + ref_info.ref_key;
          break;
        }
        case "O":
        {
          nurl = "../pda/order.asp?opdr_key=" + ref_info.ref_key;
          break;
        }
      }
      ROFIELD("fld", L("lcl_fin_referentie"), ref_info.referentie, {moreinfo : nurl}); // Referentie.
      ROFIELD("flddate", L("lcl_fin_findate"), toDateString(fin_factuur.fin_date)); // Factuur datum
      ROFIELD("fld", L("lcl_fin_invoice_nr_extern"), fin_factuur.fin_nr); // Factuurnummer (extern).
      ROFIELD("fldshort", L("lcl_fin_divide_period"), fin_factuur.fin_boekm != null? fin_factuur.fin_boekm : ""); // Verdeelperiode
      ROFIELD("fld", L("lcl_fin_debtor_nr"), fin_factuur.fin_debiteur, {suppressEmpty: true}); // Eigen debiteurnummer
      ROFIELD("fld", L("lcl_shared_charge_type"), fin_factuur.fin_costsrt); // Kostensoort
      ROFIELD("fld", L("lcl_fin_goedkeurder"), fin_factuur.fin_perslid_goedkeur, {suppressEmpty: true}); // Goedkeurder.
      ROFIELD("fld", L("lcl_shared_created_by"), fin_factuur.fin_perslid_user, {suppressEmpty: true}); // Aangemaakt door
      ROFIELD("fld", L("lcl_fin_fin_status"), fin_factuur.fin_status_oms); // Factuur status
      ROFIELD("fldremark", L("lcl_fin_remark"), (fin_key != -1? fin_factuur.fin_opm : ""), {suppressEmpty: true, multi: true});

    //BLOCK_START({collapsed: true, title: L("lcl_fin_invoicerows")});
        sql = "SELECT fr.fin_factuurregel_key"
                   + "     , fr.fin_factuurregel_totaal"
                   + "     , fr.fin_factuurregel_omschrijving"
                   + "  FROM fin_factuurregel fr"
                   + " WHERE fr.fin_factuur_key = " + fin_key
                   + " ORDER BY fr.fin_factuurregel_nr, fr.fin_factuurregel_key ";
        oRs = Oracle.Execute(sql);
        GRID_START(2);
        while (!oRs.eof) {
           COL_START(1);
                ROFIELD("fldfinreg1", null, oRs.fields("fin_factuurregel_omschrijving").value );
           COL_END();
           COL_START(2);
                ROFIELD("fldfinreg2", null, S("currency_pref")+safe.curr(oRs.fields("fin_factuurregel_totaal").value));
           COL_END();
            oRs.movenext();
         }
         GRID_END();

    //BLOCK_END();

    // Plus flexkenmerken
    generateFlexKenmerkCode ({
       fnpre     : function () { BLOCK_START({collapsed: true, title: L("lcl_fin_flexblok")}); },
       fnpost    : BLOCK_END,
       fin_key: fin_key,
       kenmerk_niveau: "F",
       reado          : true,
       mobile: true
    });

    CONTROLGROUP_START();
          if (this_fin.canAccept)
          {
            BUTTON(L("lcl_approve"), {click: "fin_approve()", dataicon: "check"});
            BUTTON(L("lcl_reject"),  {click: "fin_reject()",  dataicon: "delete"});
          }
          trackinglines = mobile.hastrackingpage('factuur', fin_key);
          if (trackinglines > 0) {
            BUTTON(L("lcl_history"), {linkid: "#page-2-"+fin_key, dataicon: "bullets", transition: "pop", datarel: "dialog"});
          }

    CONTROLGROUP_END();
    CONTENT_END();
    FOOTER();
    PAGE_END();

    if (trackinglines > 0) {
        PAGE_START({id: "page-2-"+fin_key})
        mobile.trackingpage('factuur', fin_key, subject);
        PAGE_END();
    }

%>
</body>
</html>

