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

     File:         bes_edit_srtdeel_save.asp
     Description:  SUBMIT-form
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../shared/save2db.inc" -->

<% FCLTHeader.Requires({ plugins:["jQuery"] }) %>
<%
  var authparams = user.checkAutorisation("WEB_BESMSU");
  var srtdeel_key = getQParamInt( "srtdeel_key", "-1" );

  var fields =  [ { dbs: "bes_srtgroep_key",         typ: "key",      frm: "srtgroep" },
                  { dbs: "bes_srtdeel_omschrijving", typ: "varchar",  frm: "omschrijving" },
                  { dbs: "bes_srtdeel_nr",           typ: "varchar",  frm: "srtdeel_nr" },
                  { dbs: "bes_srtdeel_eenheid",      typ: "varchar",  frm: "srtdeel_eenheid" },
                  { dbs: "bes_srtdeel_btw",          typ: "float",    frm: "btw" },
                  { dbs: "bes_srtdeel_image",        typ: "varchar",  frm: "image" },
                  { dbs: "prs_bedrijf_key",          typ: "key",      frm: "lev_key" },
                  { dbs: "bes_srtdeel_vervaldatum",  typ: "date",     frm: "verval" },
                  { dbs: "bes_srtprod_key",          typ: "key",      frm: "srtprod_key" },
                  { dbs: "bes_srtdeel_veelvoud",     typ: "number",   frm: "veelvoud" },
                  { dbs: "bes_srtdeel_minimum",      typ: "number",   frm: "minimum" },
                  { dbs: "bes_srtdeel_prsflex",      typ: "check",    frm: "prsflex" },
                  { dbs: "bes_srtdeel_preview",      typ: "check",    frm: "preview" },
                  { dbs: "bes_srtdeel_opmerking",    typ: "varchar",  frm: "opmerking", len: 2000 },
                  { dbs: "bes_srtdeel_voorraadmin",  typ: "number",   frm: "voorraadmin" },
                  { dbs: "bes_srtdeel_voorraadmax",  typ: "number",   frm: "voorraadmax" },
                  { dbs: "bes_srtdeel_voorraadfactor", typ: "number", frm: "voorraadfactor" },
                  { dbs: "bes_srtdeel_maxbestel",    typ: "check0",   frm: "maxbestel" },
                  { dbs: "bes_srtdeel_wijzigdagen",  typ: "number",   frm: "wijzigdagen" },
                  { dbs: "bes_srtdeel_annuleerdagen",  typ: "number", frm: "annuleerdagen" },
                  { dbs: "bes_srtdeel_depotverdeelpct",  typ: "number", frm: "depotverdeelpct" },
                  { dbs: "bes_staffeltabel_key",     typ: "key",      frm: "staffel" },
                  { dbs: "bes_srtdeel_notitie",      typ: "varchar",  frm: "notitie"}];

var warning = "";
if (srtdeel_key > 0)
  {
    sql = buildUpdate("bes_srtdeel", fields)
        + "     bes_srtdeel_key = " + srtdeel_key;

    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
else
  {
    fields.push({  dbs: "bes_srtdeel_key",         typ: "key",      seq: "bes_s_bes_srtdeel_key" });
    var besIns = buildInsert("bes_srtdeel", fields);
    var srtdeel_key = besIns.sequences["bes_srtdeel_key"];
    sql = besIns.sql;
    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
%>
<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script>
        $(document).ready(function () {
            FcltMgr.closeDetail(window, { srtdeel_key: <%=srtdeel_key%>,
                                          warning: "<%=safe.jsstring(warning)%>",
                                          keepForm: <%=warning?"true":"false"%>
                                         });
         } );
    </script>
  </head>
  <body>
  </body>
</html>
