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

    File:          bes_bestellevr_list.asp
    Beschrijving:  Toont levering info van een bestelopdracht
    Note:

*/%>
<!--#include file="../Shared/common.inc"-->
<!--#include file="../Shared/status.inc"-->
<!--#include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="bes.inc" -->
<%
    var outputmode = getQParamInt("outputmode", 0);

    var opdr_key  = getQParamInt('opdr_key');

    var bes_bestelopdr = bes.bestelopdracht_info(opdr_key);
    var bes_bestelling = bes.bestelling_info(bes_bestelopdr.bes_key_str[0]);

    var this_bestelopdr = bes.func_enabled_bestelopdracht(opdr_key);
    var this_bestelling = bes.func_enabled_bestelling(bes_bestelling)
    var hasBOread = this_bestelopdr.canReadBOF || this_bestelopdr.canReadBOR;

    // Ik moet leesrechten (BESBOF, BESBOR of BESBAC) hebben of ik moet kostenplaatsverantwoordelijke zijn om de opdracht in te mogen zien.
    user.auth_required_or_abort(this_bestelopdr.canReadAny || this_bestelling.isVerantwoordelijke);

%>
<html>
  <head>
<%  FCLTHeader.Generate({ outputmode: outputmode }); %>
  </head>
    <script>
      function bes_opdr_deliver()
      {
        url = "../bes/opdr_delivery.asp?opdr_key=<%=opdr_key%>&is_multi=0";
        FcltMgr.openModalDetail(url, L("lcl_bes_delivery"), {xwidth: 800, callback: FcltMgr.reload});
      }

    </script>
  <body class="listmode">
<%

    var sql = "SELECT bes_bestellevr_opmerk, "
            + "       bes_bestellevr_pakbon, "
            + "       bes_bestellevr_datum, "
            + "       bes_srtdeel_nr, "
            + "       bes_srtdeel_omschrijving, "
            + "       bes_bestellevr_item_aantal, "
            + "       prs_perslid_naam_friendly"
            + "  FROM bes_bestellevr_item  bbli, "
            + "       bes_bestellevr       bbl, "
            + "       bes_bestelopdr       bbo, "
            + "       bes_bestelopdr_item  bbi, "
            + "       bes_bestelling_item  bi, "
            + "       bes_srtdeel          bs, "
            + "       prs_v_perslid_fullnames_all p "
            + " WHERE     bbo.bes_bestelopdr_key = " + opdr_key
            + "       AND bbo.bes_bestelopdr_key = bbi.bes_bestelopdr_key "
            + "       AND bbli.bes_bestelopdr_item_key = bbi.bes_bestelopdr_item_key "
            + "       AND bbl.bes_bestellevr_key = bbli.bes_bestellevr_key "
            + "       AND bi.bes_bestelopdr_item_key = bbi.bes_bestelopdr_item_key "
            + "       AND bi.bes_Srtdeel_key = bs.bes_srtdeel_key "
            + "       AND p.prs_perslid_key (+) = bbl.prs_perslid_key" // outer join voor hard verwijderde persoon
            + " ORDER BY bes_bestellevr_datum";

    var buttons = [];
    if (this_bestelopdr.canDeliver)
      buttons.push({icon: "fa-bell", title: L("lcl_bes_delivery"), action:"bes_opdr_deliver()" });

    buttons.push({ icon: "fa-fclt-refresh", title: L("lcl_refresh"), action: "FcltMgr.reload()" });


    var rst = new ResultsetTable({ sql:sql,
                                   ID: "deliverytable",
                                   outputmode: outputmode,
                                   showAll: getQParamInt("showall", 0),
                                   buttons: buttons
                                 });

    rst.addColumn(new Column({caption: L("lcl_bes_bestellevr_pakbon"), content: "bes_bestellevr_pakbon", datatype: "varchar" }));
    rst.addColumn(new Column({caption: L("lcl_date_time"), content: "bes_bestellevr_datum", datatype: "datetime"}));
    rst.addColumn(new Column({caption: L("lcl_mld_changedby"), content: "prs_perslid_naam_friendly", datatype: "varchar"}));
    rst.addColumn(new Column({caption: L("lcl_bes_comment"), content: "bes_bestellevr_opmerk", datatype: "varchar"}));
    rst.addColumn(new Column({caption: L("lcl_bes_srtdeel_nr"), content: "bes_srtdeel_nr", datatype: "varchar"}));
    rst.addColumn(new Column({caption: L("lcl_bes_srtdeel"), content: "bes_srtdeel_omschrijving", datatype: "varchar"}));
    rst.addColumn(new Column({caption: L("lcl_bes_delivered_now"), content: "bes_bestellevr_item_aantal", datatype: "number"}));


    var cnt = rst.processResultset();
%>
  </body>
</html>
<% ASPPAGE_END(); %>
