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

     File:               opdr_schedule_save.asp.asp
     Description:        Plannen van een specifieke opdracht.
     Parameters:
        opdr_key         Opdracht key van de opdracht die gepland moet worden.
*/ %>

<%
var JSON_Result = true;

var mode = getFParamInt("mode");
var opdr_key = getFParamInt("opdr_key");
var note = getFParam("note", "");
var opdr_note_key = getFParamInt("note_key", -1); // Bij single plannen is de notitie al opgeslagen (multi doen we nog niet.
if (opdr_key > 0)
    var LOCKED_USER_OK = { "xmlnode": "opdracht", "key": opdr_key };
%>

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

<%
/***** Get webform parameters *****/
var this_opdr = mld.func_enabled_opdracht(opdr_key); // wat mag ik zoal op deze opdracht

user.anything_todo_or_abort(this_opdr.canPlanDatesChange && (S("mld_ord_edit_plandates") & 2) && !(mode == 2 && !(S("mld_use_plandate2") & 2)));
/***** End get webform parameters *****/
var result = { message: "", success: false };

// Blijkbaar mogen we Plannen.
var mld_opdr = this_opdr.mld_opdr;

lcl.set_dialect(mld_opdr.opdr_type, "MLD_TYPEOPDR_KEY");

// Deze velden altijd opslaan
if (mode == 1)
  var fields = [{dbs: "mld_opdr_plandatum",          typ: "datetime", frm: "date_plan",  track: L("lcl_opdr_plandate")}];
else // (mode == 2)
  var fields = [{dbs: "mld_opdr_plandatum2",         typ: "datetime", frm: "date_plan2", track: L("lcl_opdr_plandate2")}];

var mldUpd = buildTrackingUpdate("mld_opdr", "mld_opdr_key = " + opdr_key, fields);
if (mldUpd && mldUpd.trackarray.length)
{
  Oracle.Execute(mldUpd.sql);
  var ins_srtdiscipline_prefix = mld.mld_prefix(mld_opdr.mld_key);
  var formattedID = ins_srtdiscipline_prefix + mld_opdr.mld_key + "/" + mld_opdr.volgnr;
  if (mode == 1)
    var tracking_key = mld.trackopdrplandatumupdate(opdr_key, L("lcl_ord_is_ordpldtrack").format(formattedID) + "\n" + mldUpd.trackarray.join("\n"));
  else // (mode == 2)
    var tracking_key = mld.trackopdrplandatum2update(opdr_key, L("lcl_ord_is_ordpl2track").format(formattedID) + "\n" + mldUpd.trackarray.join("\n"));

  // Registeren bij de laatste notitie
  if (opdr_note_key > 0)
  {
    var sql = "UPDATE mld_opdr_note"
            + "   SET fac_tracking_key = " + tracking_key
            + " WHERE mld_opdr_note_key = " + opdr_note_key;
    Oracle.Execute(sql);
  }
}

result.success = true;

Response.Write(JSON.stringify(result));
%>
<% ASPPAGE_END(); %>
