414 lines
18 KiB
C++
414 lines
18 KiB
C++
<%
|
|
/*
|
|
File: res.inc
|
|
Description: defines usefull timestamps (both serverside and clientside)
|
|
take holidays into accounts
|
|
Globals defined:
|
|
tConfirm js date of tConfirm
|
|
tCancel js date of tCancel
|
|
tExpire js date of tExpire
|
|
tNow js date of tNow
|
|
Context:
|
|
Note: Also takes holidays into account
|
|
*/
|
|
|
|
res = {
|
|
trackaction:
|
|
function (paction, res_key, poms) /* paction is 'RESNEW', 'RESUPD', 'RESAFM' of 'RESDEL' */
|
|
{
|
|
if (typeof poms == 'undefined')
|
|
//pcode VARCHAR2 , prefkey NUMBER, puserkey NUMBER, pdatum DATE, poms VARCHAR2
|
|
var sql = "BEGIN fac.trackaction('"+paction+"', "+res_key+", "+user_key+", NULL, NULL); END;"
|
|
else
|
|
var sql = "BEGIN fac.trackaction('"+paction+"', "+res_key+", "+user_key+", NULL, '"+poms+"'); END;"
|
|
Oracle.Execute( sql );
|
|
},
|
|
|
|
dirtlevel:
|
|
{
|
|
ruimte:
|
|
{
|
|
clean:0,
|
|
//licht
|
|
//middel
|
|
//zwaar
|
|
noroom : 0x100, // 0b000100000000, // Geen alg_ruimte/opstel_key ingevuld
|
|
notavailable : 0x200 // 0b001000000000 // Niet beschikbaar op gekozen tijdstip
|
|
},
|
|
artikel:
|
|
{
|
|
clean:0,
|
|
//licht
|
|
//middel
|
|
timechanged : 0x000000010000, // Parent gewijzigd en wij mee gewijzigd
|
|
timenotchanged: 0x000000100000, // Parent gewijzigd maar wij niet mee gewijzigd
|
|
//zwaar
|
|
notallowed : 0x000100000000 // Niet toegestaan in deze ruimte
|
|
},
|
|
deel:
|
|
{
|
|
clean:0,
|
|
//licht
|
|
//middel
|
|
timechanged : 0x000000010000, // Parent gewijzigd en wij mee gewijzigd
|
|
timenotchanged: 0x000000100000, // Parent gewijzigd maar wij niet mee gewijzigd
|
|
//zwaar
|
|
notallowed : 0x000100000000, // Niet toegestaan in deze ruimte
|
|
notavailable : 0x001000000000 // Niet beschikbaar op tijdstip
|
|
}
|
|
},
|
|
|
|
// Verwijder de afspraak die eventueel gekoppeld was aan rsv_ruimte_key
|
|
// (JGL: Eigenlijk moet dit gewoon cascading door een trigger gebeuren)
|
|
DeleteResAfspraak: function DeleteResAfspraak (rsv_ruimte_key)
|
|
{
|
|
var sql;
|
|
var oRs;
|
|
// delete parkeerplaatsen gebeurt wel met behulp van CASCADE (bez_bezoekers)
|
|
|
|
// delete bezoekers
|
|
var sql = "DELETE FROM bez_bezoekers"
|
|
+ " WHERE bez_afspraak_key in "
|
|
+ " (SELECT ba.bez_afspraak_key"
|
|
+ " FROM bez_afspraak ba"
|
|
+ " WHERE ba.res_rsv_ruimte_key = " + rsv_ruimte_key + ")";
|
|
Oracle.Execute( sql );
|
|
|
|
// delete afspraak
|
|
sql = "DELETE FROM bez_afspraak"
|
|
+ " WHERE res_rsv_ruimte_key = " + rsv_ruimte_key;
|
|
Oracle.Execute( sql );
|
|
},
|
|
|
|
res_ruimte_info: function _res_ruimte(res_ruimte_key)
|
|
{
|
|
var result = { res_ruimte_key: res_ruimte_key,
|
|
RoomConfigs: [] };
|
|
|
|
var sql = "SELECT res_ruimte_nr,"
|
|
+ " res_ruimte_omschrijving,"
|
|
+ " res_disc_params_aantalreq,"
|
|
+ " res_disc_params_kosten,"
|
|
+ " ins_discipline_kpnverplicht,"
|
|
+ " COALESCE(res_ruimte_begintijd, " + res_t1 + ") begintijd,"
|
|
+ " COALESCE(res_ruimte_eindtijd, " + res_t2 + ") eindtijd,"
|
|
+ " rr.res_discipline_key"
|
|
+ " FROM res_ruimte rr, res_disc_params rdp, res_discipline rd"
|
|
+ " WHERE rr.RES_RUIMTE_KEY = " + res_ruimte_key
|
|
+ " AND rr.res_discipline_key = rd.ins_discipline_key "
|
|
+ " AND rr.res_discipline_key = rdp.res_ins_discipline_key"
|
|
var oRs = Oracle.Execute( sql );
|
|
result.ruimte_nr = oRs("res_ruimte_nr").Value,
|
|
result.ruimte_omschrijving = oRs("res_ruimte_omschrijving").Value,
|
|
result.aantalreq = oRs("res_disc_params_aantalreq").Value;
|
|
result.kosten = oRs("res_disc_params_kosten").Value;
|
|
result.kpnverplicht = oRs("ins_discipline_kpnverplicht").Value;
|
|
result.discipline_key = oRs("res_discipline_key").Value;
|
|
result.begintijd = oRs("begintijd").Value;
|
|
result.eindtijd = oRs("eindtijd").Value;
|
|
if (result.begintijd < res_t1) result.begintijd = res_t1;
|
|
if (result.eindtijd > res_t2) result.eindtijd = res_t2;
|
|
if (result.begintijd > result.eindtijd) result.begintijd = result.eindtijd;
|
|
|
|
var sql = "select RES_RUIMTE_OPSTEL_KEY,"
|
|
+ " RES_RUIMTE_OPSTEL_BEZOEKERS,"
|
|
+ " RES_RUIMTE_OPSTEL_DEFAULT,"
|
|
+ " ro.RES_OPSTELLING_KEY,"
|
|
+ " RES_OPSTELLING_OMSCHRIJVING"
|
|
+ " FROM RES_RUIMTE rr, RES_RUIMTE_OPSTELLING rro, RES_OPSTELLING ro"
|
|
+ " WHERE rr.RES_RUIMTE_KEY = " + res_ruimte_key
|
|
+ " AND rr.RES_RUIMTE_KEY = rro.RES_RUIMTE_KEY"
|
|
+ " AND rro.res_opstelling_key = ro.res_opstelling_key"
|
|
+ " ORDER BY res_opstelling_volgnr";
|
|
var oRs = Oracle.Execute( sql );
|
|
|
|
while( !oRs.eof )
|
|
{
|
|
result.RoomConfigs.push({ ruimte_opstel_key: oRs("RES_RUIMTE_OPSTEL_KEY").value,
|
|
ruimte_opstel_default: oRs("RES_RUIMTE_OPSTEL_DEFAULT").value,
|
|
opstelling_omschrijving: oRs("RES_OPSTELLING_OMSCHRIJVING").value,
|
|
opstelling_key: oRs("RES_OPSTELLING_KEY").value,
|
|
bezoekers: oRs("RES_RUIMTE_OPSTEL_BEZOEKERS").value });
|
|
oRs.MoveNext();
|
|
}
|
|
oRs.close();
|
|
|
|
return result;
|
|
},
|
|
|
|
_tConfirm: null,
|
|
_tCancel: null,
|
|
_tExpire: null,
|
|
_tCatExpire: null,
|
|
_tNow: null,
|
|
_require_times: function ()
|
|
{
|
|
if (!this._tConfirm)
|
|
{
|
|
var dt = new Date();
|
|
var hour = dt.getHours();
|
|
var min = dt.getMinutes();
|
|
|
|
var sysdate_start = dt.beginToSQL(); // Begin van de dag nemen
|
|
var time_string = dt.toTimeString();
|
|
|
|
var in_time = true;
|
|
if (t_expire_limit != -1) {
|
|
in_time = (time_string < t_expire_limit); // Ben ik voor of na de t_expire_limit tijd, waarna het niet meer mogelijk is door de FrontEnd aanpassingen te maken
|
|
}
|
|
|
|
var in_time_cat = true;
|
|
if (t_catExpire_limit != -1) {
|
|
in_time_cat = (time_string < t_catExpire_limit); // Ben ik voor of na de t_catExpire_limit tijd, waarna het niet meer mogelijk is door de FrontEnd aanpassingen te maken
|
|
}
|
|
|
|
sql = "SELECT mld_p_mld_datumtijd.DatumTijdPlusUitvoerTijd(SYSDATE, " + res_confirm + ", 'DAGEN'),"
|
|
sql += " mld_p_mld_datumtijd.DatumTijdPlusUitvoerTijd(SYSDATE, " + res_cancel + ", 'DAGEN'),"
|
|
sql += " mld_p_mld_datumtijd.DatumTijdPlusUitvoerTijd(" + ((t_expire_limit == -1)?"sysdate":sysdate_start) + ", " + (res_expire + (in_time?0:1)) + ", 'DAGEN'),"
|
|
sql += " mld_p_mld_datumtijd.DatumTijdPlusUitvoerTijd(" + ((t_catExpire_limit == -1)?"sysdate":sysdate_start) + ", " + (res_catExpire + (in_time_cat?0:1)) + ", 'DAGEN')"
|
|
sql += " FROM DUAL"
|
|
|
|
oRs = Oracle.Execute( sql );
|
|
this._tConfirm = new Date(oRs(0).Value);
|
|
this._tCancel = new Date(oRs(1).Value);
|
|
this._tExpire = new Date(oRs(2).Value);
|
|
this._tCatExpire = new Date(oRs(3).Value);
|
|
this._tNow = new Date();
|
|
oRs.Close()
|
|
}
|
|
},
|
|
tConfirm: function ()
|
|
{
|
|
this._require_times();
|
|
return this._tConfirm;
|
|
},
|
|
tCancel: function ()
|
|
{
|
|
this._require_times();
|
|
return this._tCancel;
|
|
},
|
|
tExpire: function ()
|
|
{
|
|
this._require_times();
|
|
return this._tExpire;
|
|
},
|
|
tCatExpire: function ()
|
|
{
|
|
this._require_times();
|
|
return this._tCatExpire;
|
|
},
|
|
tNow: function ()
|
|
{
|
|
this._require_times();
|
|
return this._tNow;
|
|
},
|
|
|
|
clientTimeVars: function _clientTimeVars()
|
|
{
|
|
%>
|
|
<script type="text/javascript">
|
|
var tConfirm = new Date(<%=this.tConfirm().valueOf()%>)
|
|
var tCancel = new Date(<%=this.tCancel().valueOf()%>)
|
|
var tExpire = new Date(<%=this.tExpire().valueOf()%>)
|
|
var tCatExpire = new Date(<%=this.tCatExpire().valueOf()%>)
|
|
var tNow = new Date(<%=this.tNow().valueOf()%>) // Server side date to use clientside!
|
|
</script>
|
|
<%
|
|
}
|
|
}
|
|
|
|
|
|
if ( !this.SamePeriodCheck )
|
|
SamePeriodCheck = false;
|
|
|
|
function shared_rooms( room_key ) {
|
|
return "select rb.RES_RUIMTE_KEY"
|
|
+ " from res_v_aanwezigalg_ruimte ra, res_v_aanwezigalg_ruimte rb"
|
|
+ " where ra.RES_RUIMTE_KEY = " + room_key
|
|
+ " and ra.alg_ruimte_key = rb.alg_ruimte_key";
|
|
}
|
|
function same_period_sql( t1, t2, t3, t4 ) {
|
|
/* [t1,t2] & [t3,t4]
|
|
|
|
return "(("+t1+" >= "+t3 +" and "+t1+" < "+t4+")" +" or ("+t3+" >= "+t1 +" and "+t3+" < "+t2+"))";
|
|
*/
|
|
|
|
return "( ("+t3+" < "+t2+")" +" and ("+t4+" > "+t1+"))";
|
|
}
|
|
|
|
function same_period_res( r1, r2 ) {
|
|
return same_period_sql( r1+".RES_RSV_RUIMTE_VAN", r1+".RES_RSV_RUIMTE_TOT",
|
|
r2+".RES_RSV_RUIMTE_VAN", r2+".RES_RSV_RUIMTE_TOT" )
|
|
}
|
|
|
|
function reserved_deel_sql( res_k, wh ) {
|
|
if(SamePeriodCheck)
|
|
return "(select rd.RES_DEEL_KEY from RES_v_aanwezigRSV_DEEL rd"
|
|
+" where "+wh+" exists ("
|
|
+ select_reservations( "a.RES_RESERVERING_KEY",
|
|
", (select RES_RSV_RUIMTE_VAN, RES_RSV_RUIMTE_TOT"
|
|
+ " from RES_V_AANWEZIGRESERVERING where RES_RESERVERING_KEY=" + res_k + ") b",
|
|
" where a.RES_RESERVERING_KEY = rd.RES_RESERVERING_KEY"
|
|
+" and (" + same_period_res('a','b') + ")" )
|
|
+"))";
|
|
else return '(select 14 FROM DUAL where 1=2)';
|
|
}
|
|
|
|
function res_deel_sql( wh, cl ) {
|
|
return "(select "+cl
|
|
+ " from RES_v_aanwezigDEEL d"
|
|
+ " where "+wh+" not exists "
|
|
+ reserved_deel_sql(res_key,'rd.RES_DEEL_KEY = d.RES_DEEL_KEY and') + ")";
|
|
}
|
|
|
|
function srt_deel_sql(wh) {
|
|
return "(select i.INS_SRTDEEL_KEY from INS_v_aanwezigDEEL i"
|
|
+ " where "+wh+" exists " + res_deel_sql('i.INS_DEEL_KEY=d.RES_INS_DEEL_KEY and',
|
|
'd.RES_INS_DEEL_KEY') + ")";;
|
|
}
|
|
|
|
function srt_groep_sql(wh) {
|
|
return "(select g.INS_SRTGROEP_KEY from INS_v_aanwezigSRTDEEL g"
|
|
+ " where "+wh+" exists " + srt_deel_sql('g.INS_SRTDEEL_KEY=i.INS_SRTDEEL_KEY and') + ")";
|
|
}
|
|
|
|
function ins_disc_sql(wh) {
|
|
return "(select sg.INS_DISCIPLINE_KEY from INS_v_aanwezigSRTGROEP sg"
|
|
+ " where " + wh
|
|
+ " exists" + srt_groep_sql('sg.INS_SRTGROEP_KEY=g.INS_SRTGROEP_KEY and') + ")";
|
|
}
|
|
|
|
function ins_discipline(cl) {
|
|
return "select "+cl+" from INS_v_aanwezigDISCIPLINE d"
|
|
+ " WHERE d.INS_DISCIPLINE_KEY IN("
|
|
+ "SELECT ins_discipline_key FROM FAC_V_WEBGEBRUIKER"
|
|
+ " WHERE PRS_PERSLID_KEY ="+user_key+")"
|
|
+ " and exists "+ins_disc_sql('d.INS_DISCIPLINE_KEY=sg.INS_DISCIPLINE_KEY and');
|
|
}
|
|
|
|
|
|
function res_ins_discipline_deel(cl, autfunction) {
|
|
__Log('autfunction :'+autfunction);
|
|
|
|
return "select "+cl+" from RES_v_aanwezigDISCIPLINE dis"
|
|
+ " WHERE ins_discipline_min_level=1"
|
|
+ " AND dis.INS_DISCIPLINE_KEY IN("
|
|
+ "SELECT g.ins_discipline_key FROM FAC_V_WEBGEBRUIKER g, FAC_FUNCTIE f "
|
|
+ "WHERE g.fac_functie_key = f.fac_functie_key "
|
|
+ "AND f.fac_functie_code = '" + autfunction + "'"
|
|
+ " AND g.fac_gebruiker_alg_level_read < 9"
|
|
+ " AND g.PRS_PERSLID_KEY ="+user_key
|
|
+ ") and dis.INS_DISCIPLINE_KEY IN"
|
|
+ "(SELECT res_discipline_key" /* DISTINCT */
|
|
+ " from res_deel R, ins_deel D"
|
|
+ " where r.res_deel_verwijder IS NULL"
|
|
+ " and R.res_ins_deel_key=D.ins_deel_key)";
|
|
}
|
|
|
|
function res_ins_discipline_artikel(cl, autfunction, alg_ruimte_key, rsv_ruimte_key, fixed_room) {
|
|
|
|
if( isNaN(alg_ruimte_key) ) {
|
|
alg_ruimte_key = 'NULL';
|
|
}
|
|
|
|
if( isNaN(rsv_ruimte_key) ) {
|
|
rsv_ruimte_key = 'NULL';
|
|
}
|
|
|
|
if( rsv_ruimte_key == 'NULL' && alg_ruimte_key == 'NULL' ) {
|
|
%>
|
|
<p><%=lcl_internal_error %>: res.inc</p>
|
|
<%
|
|
Response.End;
|
|
}
|
|
|
|
return "select "+cl+" from RES_v_aanwezigDISCIPLINE d"
|
|
+ " WHERE ins_discipline_min_level=2"
|
|
+ " AND d.INS_DISCIPLINE_KEY IN ("
|
|
+ " SELECT ins_discipline_key FROM FAC_V_WEBGEBRUIKER g, FAC_FUNCTIE f "
|
|
+ " WHERE g.fac_functie_key = f.fac_functie_key "
|
|
+ " AND f.fac_functie_code = '" + autfunction + "' "
|
|
+ " AND g.PRS_PERSLID_KEY ="+user_key
|
|
+ " AND d.INS_DISCIPLINE_KEY IN"
|
|
// RES_V_SRTARTIKEL_ONRGOED i.p.v. res_v_srtartikel_ruimte:
|
|
// niet alleen kijken naar max(prio) 'R' (ruimte) maar ook naar onderliggende prio's 'L' (locatie) en 'G' (gebouw)
|
|
// In de view res_v_srtartikel_ruimte wordt alleen naar de maximale prio gekeken van een bepaalde alg_ruimte_key
|
|
+ " (SELECT res_discipline_key FROM res_v_srtartikel_onrgoed "
|
|
+ " WHERE 1 = 1 "
|
|
+ (fixed_room? " AND alg_onrgoed_niveau = 'R'":"")
|
|
+ (!isNaN(alg_ruimte_key)? " AND alg_ruimte_key = "+alg_ruimte_key+ ")) "
|
|
: (!isNaN(rsv_ruimte_key)? " AND alg_ruimte_key IN"
|
|
+ " (SELECT alg_ruimte_key FROM res_v_rsv_ruimte_2_alg_ruimte "
|
|
+ " WHERE res_alg_ruimte_verwijder IS NULL AND res_rsv_ruimte_key="+rsv_ruimte_key+")))":""))
|
|
+ " ORDER BY 2";
|
|
}
|
|
|
|
// TODO: p_alg_ruimte_key zelf bepalen uit p_rsv_ruimte_key
|
|
function getReservedObjectTypes (p_alg_ruimte_key, p_rsv_ruimte_key, p_select_fields, p_loc_key, p_sdisc, p_group_by) {
|
|
__Log("p_alg_ruimte_key: " + p_alg_ruimte_key + ", p_rsv_ruimte_key: " + p_rsv_ruimte_key);
|
|
if (isNaN(p_alg_ruimte_key)||!p_alg_ruimte_key) p_alg_ruimte_key = -1;
|
|
var sql1 = "SELECT " + p_select_fields
|
|
+ " FROM ins_srtdeel sd, ins_deel d, res_v_aanwezigdeel r "
|
|
+ ", (SELECT d.alg_regio_key, l.alg_district_key, l.alg_locatie_key, g.alg_gebouw_key, v.alg_verdieping_key, r.alg_ruimte_key "
|
|
+ " FROM "
|
|
+ (!isNaN(p_rsv_ruimte_key)&&(p_alg_ruimte_key==-1)
|
|
? " res_v_rsv_ruimte_2_alg_ruimte rrr, "
|
|
: "")
|
|
+ " alg_district d,"
|
|
+ " alg_locatie l,"
|
|
+ " alg_gebouw g,"
|
|
+ " alg_verdieping v,"
|
|
+ " alg_ruimte r"
|
|
+ " WHERE 1=1 "
|
|
+ (!isNaN(p_rsv_ruimte_key)&&(p_alg_ruimte_key==-1)
|
|
? " AND res_rsv_ruimte_key = " + p_rsv_ruimte_key
|
|
+ " AND rrr.alg_ruimte_key = r.alg_ruimte_key"
|
|
: "")
|
|
+ ((p_alg_ruimte_key>0)
|
|
?" AND r.alg_ruimte_key = "+p_alg_ruimte_key
|
|
: "")
|
|
+ " AND r.alg_verdieping_key = v.alg_verdieping_key"
|
|
+ " AND v.alg_gebouw_key = g.alg_gebouw_key"
|
|
+ " AND g.alg_locatie_key = l.alg_locatie_key"
|
|
+ " AND l.alg_district_key = d.alg_district_key ) scope"
|
|
+ ((!isNaN(p_rsv_ruimte_key) || ((p_alg_ruimte_key>0)))
|
|
? ", res_v_deelscope ds"
|
|
: "")
|
|
+ " WHERE r.res_discipline_key="+p_sdisc
|
|
+ " AND r.res_ins_deel_key=d.ins_deel_key"
|
|
+ " AND d.ins_srtdeel_key = sd.ins_srtdeel_key"
|
|
+ ((p_loc_key > -1)
|
|
? " AND d.ins_alg_locatie_key="+p_loc_key
|
|
: "")
|
|
+ " AND d.ins_alg_ruimte_type IN ('R','T')";
|
|
|
|
if (!isNaN(p_rsv_ruimte_key) || (p_alg_ruimte_key>0)) {
|
|
sql1 += " AND "
|
|
+ " ( ds.alg_regio_key = scope.alg_regio_key"
|
|
+ " OR ds.alg_district_key = scope.alg_district_key"
|
|
+ " OR ds.alg_locatie_key = scope.alg_locatie_key"
|
|
+ " OR ds.alg_gebouw_key = scope.alg_gebouw_key"
|
|
+ " OR ds.alg_verdieping_key = scope.alg_verdieping_key"
|
|
+ " OR ds.alg_ruimte_key = scope.alg_ruimte_key"
|
|
+ " OR ds.res_deel_alg_level = -1)"
|
|
+ " AND r.res_deel_key = ds.res_deel_key"
|
|
} else { // kunnen we hier wel komen? Zelfde check komt buiten deze if ook al voor.
|
|
sql1 = discxalg3d (sql1,
|
|
"r.RES_DISCIPLINE_KEY",
|
|
"scope.alg_regio_key",
|
|
"scope.alg_district_key",
|
|
"scope.alg_locatie_key",
|
|
"scope.alg_gebouw_key",
|
|
"scope.alg_verdieping_key",
|
|
"scope.alg_ruimte_key",
|
|
autfunction,
|
|
p_sdisc);
|
|
sql1 +=" AND r.res_deel_key = ds.res_deel_key"
|
|
}
|
|
sql1 += p_group_by;
|
|
return sql1;
|
|
}
|
|
|
|
|
|
%>
|