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

    File:         bes_show_srtprod.asp
    Description:  Details van een artikel
    Parameters:   srtprod_key

    Context:
    Note:

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="../Shared/bedrijfselector.inc" -->

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

var srtprod_key  = getQParamInt("srtprod_key", -1);

var authparams = user.checkAutorisation("WEB_BESMSU");

if (srtprod_key > 0)
{
    sql = "SELECT bes_srtprod_omschrijving,"
        + "       bes_srtprod_btw,"
        + "       bes_srtprod_eenheid,"
        + "       bes_srtprod_nr,"
        + "       prs_bedrijf_key,"
        + "       bes_srtprod_vervaldatum ,"
        + "       bes_srtprod_image,"
        + "       bes_srtprod_veelvoud,"
        + "       bes_srtprod_opmerking,"
        + "       bes_grootheid_key,"
        + "       bes_grootheid_getal,"
        + "       bes_srtprod_verwijder"
        + "  FROM bes_srtprod d"
        + " WHERE d.bes_srtprod_key = " + srtprod_key

    oRs = Oracle.Execute(sql);

    var art = { srtprod_key: srtprod_key,
                omschrijving: oRs("bes_srtprod_omschrijving").Value,
                btw: oRs("bes_srtprod_btw").Value,
                eenheid: oRs("bes_srtprod_eenheid").Value,
                grootheid_key: oRs("bes_grootheid_key").Value,
                grootheid_getal: oRs("bes_grootheid_getal").Value,
                nr: oRs("bes_srtprod_nr").Value,
                bedrijf_key: oRs("prs_bedrijf_key").Value,
                vervaldatum : oRs("bes_srtprod_vervaldatum").Value,
                image: oRs("bes_srtprod_image").Value,
                opmerking: oRs("bes_srtprod_opmerking").Value,
                verwijder: oRs("bes_srtprod_verwijder").Value
            }

    oRs.Close();
}
else
    var art = {};
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script  type="text/javascript" >
      function bes_submit()
      {
          document.activeElement.blur(); // trigger laatste onChanges
          if (!validateForm("u2"))
              return false;
          document.forms.u2.submit();
      }

      function bes_cancel()
      {
          FcltMgr.closeDetail(window, { cancel: true } );
      }
    </script>
  </head>
  <body id="editbody">
<%  var buttons = [];

    var buttons =  [ {title: L("lcl_submit"), action:"bes_submit()", icon: "opslaan.png" },
                     {title: L("lcl_cancel"), action:"bes_cancel()", icon: "undo.png" } ];
    IFRAMER_HEADER(L("lcl_bes_srtprod_frame"), buttons);
%>
    <div id="show">
      <form name="u2"
            action="bes_edit_srtprod_save.asp?srtprod_key=<%=srtprod_key%>"
            method="post"
            target="hidFrameSubmit"
            onSubmit="bes_submit()">
<%      BLOCK_START("besArtikel", L("lcl_bes_srtprodblok"));

        // TODO: groep kunne kiezen; verplicht of..?
        RWFIELDTR("srtprod_nr",      "fld", L("lcl_bes_srtdeel_nr"), art.nr, { maxlength: 100 });
        RWFIELDTR("omschrijving",    "fld", L("lcl_bes_srtdeel_oms"), art.omschrijving, { required: true, maxlength: 100 });
        // TODO; catalogus en groep
        ROFIELDTR("fld", L("lcl_bes_discipline"), "@TODO");
        ROFIELDTR("fld", L("lcl_bes_srtgroup"), "@TODO");
        RWFIELDTR("srtprod_eenheid", "fld", L("lcl_bes_unity"), art.eenheid, { maxlength: 32 });

        RWFIELDTR("grootheid_getal", "fld", L("lcl_bes_grootheidnorm"), art.grootheid_getal, { maxlength: 32 });
        var sql = "SELECT bes_grootheid_key, "
            + "       bes_grootheid_naam"
            + "  FROM bes_grootheid"
            + " WHERE bes_grootheid_verwijder IS NULL";
        FCLTselector("grootheid", sql,
                    {  label: L("lcl_bes_grootheid"),
                       initKey: art.grootheid_key,
                       emptyOption: ""
                    });

        RWFIELDTR("image", "fld", L("lcl_bes_image"), art.image);
        // TODO: iets met grootheid en hoeveelheid
        BLOCK_END();

        BLOCK_START("besArtikelBestel", L("lcl_bes_srtdeelbestelblok"));
        FCLTbedrijfselector("lev_key", // supplier
                           "sg_lev",
                          { companyKey: art.bedrijf_key,
                            label: L("lcl_bes_producer"),
                            trclass: "primsearch",
                            filtercode: "L",
                            whenEmpty: L("lcl_search_generic")
                          });

        FCLTcalendar( "verval",
            {
                datum: art.vervaldatum==null?null:new Date(art.vervaldatum),
                label: L("lcl_bes_vervaldatum"),
                initEmpty: art.vervaldatum==null
            });

        RWFIELDTR("veelvoud", "fldshort", L("lcl_bes_veelvoud"), art.veelvoud);
        RWFIELDTR("btw", "fldshort", L("lcl_btw_percentage"), art.btw);
        RWTEXTAREATR("opmerking", "fld", L("lcl_bes_opmerking"), art.opmerking);

        BLOCK_END();
IFACE.FORM_END();
%>
      </form>
    </div>
    <iframe src="../Shared/empty.html" name="hidFrameSubmit" style="display:none"></iframe>
  </body>
</html>
