294 lines
14 KiB
C++
294 lines
14 KiB
C++
<% /*
|
|
$Revision$
|
|
$Id$
|
|
|
|
File: opdr_edit_note.inc
|
|
Description: Functie vooor het echte bewaren van een melding notitie
|
|
Context: Vanuit opdr_edit_note.asp & /api2/model_notes.inc
|
|
|
|
*/
|
|
%>
|
|
<!-- #include file="../Shared/notes.inc" -->
|
|
<%
|
|
|
|
function _translate_for_api(params, jsondata) {
|
|
if (typeof jsondata !== "undefined") { // Kort translate voor model_notes.inc (API2); (indien van toepassing)
|
|
params.isApi = true;
|
|
params.flag = jsondata.flag;
|
|
params.notifyFE = jsondata.notify_requestor;
|
|
params.notifyBO = jsondata.notify_backoffice;
|
|
params.notifyUITV = jsondata.notify_executor;
|
|
params.action2FE = jsondata.action_to_requestor;
|
|
params.action2BO = jsondata.action_to_backoffice;
|
|
params.action2UITV = jsondata.action_to_executor;
|
|
}
|
|
}
|
|
function _set_actiecode(params, jsondata) {
|
|
var opdr_key = params.filter.parent_key;
|
|
var this_opdr = params.func_enabled;
|
|
var mld_opdr = this_opdr.mld_opdr;
|
|
var result = {};
|
|
_translate_for_api(params, jsondata);
|
|
|
|
var newActiecode = 0;
|
|
if (mld_opdr.actiecode & 1 && this_opdr.myRole === 4 || params.notifyBO) { // Als de actie bij de BO staat, of als de BO genotificeerd gaat worden
|
|
newActiecode += 128; // BO attentie
|
|
}
|
|
if (mld_opdr.actiecode & 4 && this_opdr.myRole !== 4 || params.notifyUITV) { // Als de actie bij de UITV staat, of als de UITV genotificeerd gaat worden
|
|
newActiecode += 512; // UITV attentie
|
|
}
|
|
|
|
if (S("mld_opdr_actiecode") > 0) // Doen we pingpong?
|
|
{
|
|
if (this_opdr.myRole === 4) { // Uitvoerder
|
|
if ((params.action2BO && !(mld_opdr.actiecode & 1)) || (!params.has_action2BO && mld_opdr.actiecode & 1)) { // 'Actie' naar BO
|
|
newActiecode += 1; // + BO
|
|
} else {
|
|
newActiecode += 4; // + UITV
|
|
}
|
|
} else { // if (this_opdr.myRole === 1 || this_opdr.myRole === 2), FE of FOBO
|
|
// Een openstaande vraag is beantwoord, of de actie is bij de uitvoerder gezet, of de BO heeft de actie niet teruggepakt;
|
|
if ((params.replyToAll || params.isResponse || params.action2UITV) || (mld_opdr.actiecode & 4 && !params.action2BO)) {
|
|
newActiecode += 4; // + UITV
|
|
} else {
|
|
newActiecode += 1; // + BO
|
|
}
|
|
}
|
|
} // if 'doen we opdracht ping pong'
|
|
|
|
{ // Opdracht actiecode
|
|
var sql = "UPDATE mld_opdr"
|
|
+ " SET mld_opdr_actiecode = " + newActiecode
|
|
+ (this_opdr.myRole === 2
|
|
? " , mld_opdr_laatstgezien = SYSDATE" // Als ik een FOBO ben, dan heb ik deze opdracht nu dus ook gezien
|
|
: "")
|
|
+ " WHERE mld_opdr_key = " + opdr_key;
|
|
Oracle.Execute(sql);
|
|
result.parent_reload = newActiecode != mld_opdr.actiecode;
|
|
} // \Opdracht actiecode
|
|
|
|
if (newActiecode & 1 && !(mld_opdr.actiecode & 1)) { // Actie veranderd naar [B]O, dus ook ORDA2B
|
|
shared.trackaction("ORDA2B", opdr_key);
|
|
}
|
|
|
|
if (newActiecode & 4 && !(mld_opdr.actiecode & 4)) { // Actie veranderd naar [U]ITV, dus ook ORDA2U
|
|
shared.trackaction("ORDA2U", opdr_key);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function _track_and_notify(params, jsondata) {
|
|
var opdr_key = params.filter.parent_key;
|
|
var this_opdr = params.func_enabled;
|
|
var mld_opdr = this_opdr.mld_opdr;
|
|
_translate_for_api(params, jsondata);
|
|
|
|
function notify_only(code) {
|
|
var notiSql = "SELECT fac_srtnotificatie_key"
|
|
+ " , fac_srtnotificatie_oms"
|
|
+ " FROM fac_srtnotificatie"
|
|
+ " WHERE fac_srtnotificatie_code = " + safe.quoted_sql(code);
|
|
var oRs = Oracle.Execute(notiSql);
|
|
|
|
var noti_key = oRs("fac_srtnotificatie_key").Value;
|
|
var noti_oms = L(oRs("fac_srtnotificatie_oms").Value, { autolcl: true });
|
|
oRs.Close();
|
|
|
|
var notiTextSql = "SELECT mld.opdrsprintf (" + safe.quoted_sql(noti_oms) + ","
|
|
+ " " + opdr_key + ")"
|
|
+ " FROM DUAL"
|
|
oRs = Oracle.Execute(notiTextSql);
|
|
noti_oms = oRs(0).Value;
|
|
oRs.Close();
|
|
|
|
sql = "BEGIN"
|
|
+ " fac.notifytracking (" + noti_key + ","
|
|
+ " " + user_key + ","
|
|
+ " " + safe.quoted_sql(noti_oms) + ","
|
|
+ " " + opdr_key + ");"
|
|
+ "END;"
|
|
Oracle.Execute(sql);
|
|
}
|
|
|
|
// Tracking
|
|
if (params.notifyFE) {
|
|
var tracking_key = shared.trackaction("MLDNOT", mld_opdr.mld_key);
|
|
if (params.note_key > 0) { // Registeren bij de net nieuw aangemaakte notitie
|
|
var sql = "UPDATE mld_opdr_note"
|
|
+ " SET fac_tracking_key = " + tracking_key
|
|
+ " WHERE mld_opdr_note_key = " + params.note_key;
|
|
Oracle.Execute(sql);
|
|
}
|
|
}
|
|
|
|
if (this_opdr.myRole !== 2 && params.notifyBO) {
|
|
var tracking_key = shared.trackaction("ORDNOB", mld_opdr.opdr_key);
|
|
if (params.note_key > 0) { // Registeren bij de net nieuw aangemaakte notitie
|
|
var sql = "UPDATE mld_opdr_note"
|
|
+ " SET fac_tracking_key = " + tracking_key
|
|
+ " WHERE mld_opdr_note_key = " + params.note_key;
|
|
Oracle.Execute(sql);
|
|
}
|
|
}
|
|
|
|
// Zorg ervoor dat de uitvoerder altijd een notificatie ontvangt wanneer:
|
|
// 1. De notitie zichtbaar is voor de uitvoerder (flag & 4)
|
|
// 2. EN de aanvrager (myRole === 1) of BO (myRole === 2) een notitie stuurt
|
|
// 3. EN de actie naar de uitvoerder gaat (action2UITV) OF de uitvoerder moet worden genotificeerd (notifyUITV)
|
|
if (this_opdr.myRole !== 4 && params.flag & 4 && (params.action2UITV || params.notifyUITV)) {
|
|
//notify_only("ORDNOL"); // zou niet naar technische adressen notificeren
|
|
shared.trackaction("ORDNOL", opdr_key, null, params.note_key);
|
|
}
|
|
|
|
if (!params.isApi || params.notifyFE) { // Alleen dan is deze tak van toepassing
|
|
var mld_info = mld.mld_melding_info(mld_opdr.mld_key);
|
|
var mldActiecode = mld_info.actiecode; // Huidige actiecode
|
|
if (this_opdr.myRole === 4) { // Uitvoerder
|
|
if (params.notifyFE) { // Als de FE genotificeerd gaat worden
|
|
mldActiecode |= 256; // + attentieFE
|
|
if (params.action2FE && mld_info.actiecode & 1) {
|
|
mldActiecode &= ~3; // - action2BO/FE
|
|
mldActiecode |= 2; // + action2FE
|
|
shared.trackaction("MLDA2M", mld_opdr.mld_key);
|
|
}
|
|
}
|
|
} else if (this_opdr.myRole === 1) { // Aanvrager
|
|
mldActiecode &= ~256; // - attentieFE
|
|
if (params.action2BO && !(mld_info.actiecode & 1)) {
|
|
mldActiecode &= ~3; // - action2BO/FE
|
|
mldActiecode |= 1; // + action2BO
|
|
mldActiecode |= 128; // + attentieBO
|
|
shared.trackaction("MLDA2B", mld_opdr.mld_key);
|
|
}
|
|
}
|
|
// Als de actiecode veranderd is, dan updaten
|
|
if (mldActiecode !== mld_info.actiecode) {
|
|
var sql = "UPDATE mld_melding"
|
|
+ " SET mld_melding_actiecode = " + mldActiecode
|
|
+ " WHERE mld_melding_key = " + mld_opdr.mld_key;
|
|
Oracle.Execute(sql);
|
|
}
|
|
}
|
|
}
|
|
|
|
function opdr_note_save(opdr_key, params)
|
|
{
|
|
var result = {};
|
|
var this_opdr = mld.func_enabled_opdracht(opdr_key, { forNotes: true }); // wat mag ik zoal op deze opdracht
|
|
var mld_opdr = this_opdr.mld_opdr;
|
|
lcl.set_dialect(mld_opdr.opdr_type, "MLD_TYPEOPDR_KEY");
|
|
|
|
// Met de reply-all knop kan de FE op alle onbeantwoorde vragen (van 1 opdracht) antwoord geven
|
|
params.replyToAll = this_opdr.myRole === 1 && params.action2UITV;
|
|
|
|
// Die laatste komt bijna niet voor dus wordt bijna niet uitgevoerd
|
|
user.auth_required_or_abort(this_opdr.canEditOpdrNote || this_opdr.myRole === 1 ||
|
|
(params.fromModule == "mld" && params.note_parent_key > -1 && mld.func_enabled_melding(mld_opdr.mld_key).canWriteNotes));
|
|
|
|
// Ik heb geen leesrechten op de opdracht, ik ben ook geen FE of UITV maar ik reply toch op een opdracht notitie (bij een melding), dan fungeer ik als FOBO (=2)
|
|
if (!this_opdr.canEditOpdrNote && !("myRole" in this_opdr) && params.note_parent_key > -1) {
|
|
this_opdr.myRole = 2;
|
|
}
|
|
|
|
if (params.note)
|
|
{
|
|
params.note = note;
|
|
params.module = "MLD";
|
|
params.table = "mld_opdr";
|
|
|
|
if (params.note_key > -1)
|
|
{
|
|
var sql = "SELECT mld_opdr_note_flag"
|
|
+ " , mld_opdr_note_aanmaak"
|
|
+ " FROM mld_opdr_note"
|
|
+ " WHERE mld_opdr_note_key = " + params.note_key
|
|
+ " AND mld_opdr_key = " + opdr_key;
|
|
var oRs = Oracle.Execute(sql);
|
|
var oldflag = oRs("mld_opdr_note_flag").Value;
|
|
var noteaanmaak = new Date(oRs("mld_opdr_note_aanmaak").Value);
|
|
oRs.Close();
|
|
}
|
|
|
|
var parentflag = 0;
|
|
if (params.note_parent_key > 0) {
|
|
var sql = "SELECT mld_opdr_note_flag"
|
|
+ " FROM mld_opdr_note n"
|
|
+ " WHERE n.mld_opdr_key = " + opdr_key
|
|
+ " AND mld_opdr_note_key = " + params.note_parent_key
|
|
+ (this_opdr.myRole === 2 ? "" : " AND BITAND(mld_opdr_note_flag, " + this_opdr.myRole + ") = " + this_opdr.myRole);
|
|
var oRs = Oracle.Execute(sql);
|
|
parentflag = oRs("mld_opdr_note_flag").Value;
|
|
oRs.Close();
|
|
}
|
|
|
|
params.zichtFE = params.zichtFE ? (!(params.note_parent_key > 0) || (parentflag & 1)) : 0;
|
|
params.zichtUITV = params.zichtUITV ? (!(params.note_parent_key > 0) || (parentflag & 4)) : 0;
|
|
|
|
params.flag = (params.zichtFE ? 1 : 0);
|
|
params.flag += (params.replyToAll || !params.has_zichtbaarUITV || params.zichtUITV || parentflag & 36 === 36 ? 4 : 0); // Automatisch zichtbaar voor UITV indien het een reactie is op een onbeantwoorde vraag die al zichtbaar was voor de uitvoerder
|
|
params.flag += ((oldflag & 32) || params.zichtFE && params.action2FE ? 32 : 0); // Dit is een vraag aan de FE, het heeft nog geen antwoord
|
|
params.flag += (params.ismailnote ? 64 : 0);
|
|
|
|
// Hier het daadwerkelijke opslaan van de notitie
|
|
var note_key = notes.note_save(opdr_key, params);
|
|
|
|
if (params.note_key > -1) // Bestaande notitie
|
|
{
|
|
if (!(params.flag & 4) && oldflag & 4) // Proberen ORDNOL notificatie terug te trekken. Geen garanties
|
|
{ // Merk op dat de volgorde notitie1 maken (zichtbaar),
|
|
// notitie2 maken (zichtbaar),
|
|
// notitie2 bewerken (onzichtbaarbaar maken)
|
|
// ingewikkeld is. Daarom de check op fac_notificatie_datum. Niet 100% maar goed genoeg.
|
|
var sql = "DELETE FROM fac_notificatie"
|
|
+ " WHERE fac_srtnotificatie_key = "
|
|
+ " (SELECT fac_srtnotificatie_key"
|
|
+ " FROM fac_srtnotificatie"
|
|
+ " WHERE fac_srtnotificatie_code = 'ORDNOL')"
|
|
+ " AND fac_notificatie_datum >= " + noteaanmaak.toSQL(true)
|
|
+ " AND fac_notificatie_refkey = " + opdr_key;
|
|
Oracle.Execute(sql);
|
|
}
|
|
}
|
|
else // Nieuwe notitie
|
|
{
|
|
// Korte translate omdat model_notes.inc (API2) ook graag van onderstaande functie gebruik maakt
|
|
params.filter = { "parent_key": opdr_key };
|
|
params.func_enabled = this_opdr;
|
|
params.note_key = note_key;
|
|
// \end translate
|
|
|
|
result = _set_actiecode(params);
|
|
|
|
{ // Flag
|
|
params.isResponse = false;
|
|
if (params.note_parent_key > -1) { // Ik ben een reply op een notitie
|
|
sql = "SELECT mld_opdr_note_flag"
|
|
+ " FROM mld_opdr_note"
|
|
+ " WHERE mld_opdr_key = " + opdr_key
|
|
+ " AND mld_opdr_note_key = " + params.note_parent_key;
|
|
oRs = Oracle.Execute(sql);
|
|
params.isResponse = oRs("mld_opdr_note_flag").Value & 32; // Dit is een reply op een onbeantwoorde notitie
|
|
oRs.Close();
|
|
}
|
|
|
|
if (params.replyToAll || params.isResponse) {
|
|
var sql = "UPDATE mld_opdr_note"
|
|
+ " SET mld_opdr_note_flag = BITAND(mld_opdr_note_flag, 127 - 32)"
|
|
+ " WHERE mld_opdr_key = " + opdr_key
|
|
// Bij params.replyToAll alle onbeantwoorde vragen als beantwoord markeren, anders alleen de beantwoordde
|
|
+ (params.replyToAll ? "" : " AND mld_opdr_note_key = " + params.note_parent_key);
|
|
Oracle.Execute(sql);
|
|
}
|
|
} // \Flag
|
|
|
|
_track_and_notify(params);
|
|
}
|
|
}
|
|
|
|
result.success = true;
|
|
result.opdr_key = opdr_key;
|
|
result.note_key = note_key;
|
|
return result;
|
|
}
|
|
|
|
%> |