<%@ LANGUAGE = JavaScript %>
<% /*
     $Revision$
     $Id$

     File:          mld_fix_slae_save.asp
     Description:   Het echte fixen van een sla
     Parameters:
         mld_key    Melding key van te wijzigen melding
     Context:
     Note:

*/
var JSON_Result = true;
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/json2.js" -->
<!-- #include file="../Shared/save2db.inc" -->
<!-- #include file="mld.inc" -->
<%
var mld_key = getQParamInt("mld_key");
var this_mld = mld.func_enabled_melding(mld_key);
var mld_melding = mld.mld_melding_info(mld_key);
user.auth_required_or_abort(this_mld.canFixSLA);

var sql = "SELECT fac.gettrackingdate ('MLDAFM', " + mld_key + ") datum FROM DUAL";
var oRs = Oracle.Execute(sql);
var old_afmeld = oRs("datum").Value == null?null:new Date(oRs("datum").Value);

var new_start = getFParamDate("date_from", null);
var new_afmeld = getFParamDate("date_to", null);

var mldUpd = { trackarray: [] };

if (new_start && new_start.getTime() != mld_melding.melddatum.getTime())
{
    var fields = [ { dbs: "mld_melding_datum",     typ: "datetime", val: new_start, track: L("lcl_mld_startdate") + " " } ];
    var mldUpd = buildTrackingUpdate("mld_melding", "mld_melding_key = " + mld_key, fields);
    Oracle.Execute(mldUpd.sql);
    mld_melding.melddatum = new_start;
}

if (new_afmeld && new_afmeld < mld_melding.melddatum) // Te problematisch
    new_afmeld = mld_melding.melddatum;   // Silent correctie

if (new_afmeld && new_afmeld.getTime() != old_afmeld.getTime())
{
  var sql = "BEGIN fac.backtrackaction('MLDAFM', " + mld_key + ", " + user_key + ", " + new_afmeld.toSQL(true) +"); END;"
  Oracle.Execute(sql);
  mldUpd.trackarray.push(L("lcl_mld_afgemeld") + ": " + buildTrackText("datetime", old_afmeld, new_afmeld));
  buildTrackText("datetime", old_afmeld, new_afmeld)

}
//      var formattedID = stdm_info.ins_srtdiscipline_prefix+mld_key + " ("+ stdm_info.discipline_omschrijving + "/"+ stdm_info.stdmelding_omschrijving +")";
//      mld.trackmeldingupdate(mld_key, L("lcl_mld_is_mldupdtrack").format(formattedID) + "\n" + mldUpd.trackarray.concat(flextrack).join("\n"));
if (mldUpd.trackarray.length)
    mld.trackmeldingupdate(mld_key, L("lcl_mld_is_mldupd") + "\n" + mldUpd.trackarray.join("\n"));

result = { success: true };
Response.Write(JSON.stringify(result));
Response.End;
%>