Files
Facilitor/APPL/BGT/bgt_budget.js
Erik Groener 62a2d0d8f3 FSN#39055 BCS/2000 functionaliteit in FACILITOR - customization
svn path=/Website/branches/v2017.2/; revision=36039
2017-11-17 13:09:04 +00:00

312 lines
10 KiB
JavaScript

$(document).ready(function () {
setTimeout("init_budget()", 100);
});
var kostensoort_btw = 0;
function init_budget()
{
$("#account").prop("disabled", true);
$("input#contingency").prop("disabled", true );
$("#order").prop("disabled", true);
$("#budgetdiscipline").change( change_discipline );
$("#budgetproject").change( change_project );
$("#budgetcostcategory").change( change_rubriek );
$("#costtypegroup").change( change_groep );
$("#costtype").change( change_soort );
$("#amount").change( change_amount );
$("#vat").change( change_vat );
$("#account").change( change_account );
// budgetdiscipline en budgetproject kunnen ook als gekozen filter worden meegegeven
// en worden dan als readonly velden getoond.
var v_budgetdiscipline = (typeof $("#budgetdiscipline").val() == "undefined" ? (typeof budgetdiscipline == "undefined" ? -1 : budgetdiscipline) : $("#budgetdiscipline").val() );
var v_budgetproject = (typeof $("#budgetproject").val() == "undefined" ? (typeof budgetproject == "undefined" ? -1 : budgetproject) : $("#budgetproject").val() );
var v_budgetcostcategory = (typeof $("#budgetcostcategory").val() == "undefined" ? (typeof budgetcostcategory == "undefined" ? -1 : budgetcostcategory) : $("#budgetcostcategory").val() );
var v_costtypegroup = (typeof $("#costtypegroup").val() == "undefined" ? (typeof costtypegroup == "undefined" ? -1 : costtypegroup) : $("#costtypegroup").val() );
var v_costtype = (typeof $("#costtype").val() == "undefined" ? (typeof costtype == "undefined" ? -1 : costtype) : $("#costtype").val() );
var init_niveau = "";
var init_key = -1;
if (v_budgetdiscipline != -1) { init_niveau = "D"; init_key = v_budgetdiscipline; }
if (v_budgetproject != -1) { init_niveau = "P"; init_key = v_budgetproject; }
if (v_budgetcostcategory != -1) { init_niveau = "R"; init_key = v_budgetcostcategory; }
if (v_costtypegroup != -1) { init_niveau = "G"; init_key = v_costtypegroup; }
if (v_costtype != "" && v_costtype != -1) { init_niveau = "S"; init_key = v_costtype; }
if (init_key > 0)
{
$.getJSON( "../bgt/get_bgt_info_ajax.asp",
{ req_info: "initsearch",
niveau: init_niveau,
parent_key: -1,
init_key: init_key
},
re_init_soort);
}
else
{
var data = { niveau: "D",
parents: { D: -1,
P: -1,
R: -1,
G: -1,
S: -1
}
};
re_init_soort(data);
}
init_niveau = "KP";
init_key = -1;
if ($("#account").val() != -1)
{
init_key = $("#account").val();
}
$.getJSON( "../bgt/get_bgt_info_ajax.asp",
{ req_info: "initsearch",
niveau: init_niveau,
parent_key: (v_budgetproject ? v_budgetproject : -1),
child_key: v_costtype,
init_key: init_key
},
re_init_plaats);
}
function re_init_soort(data)
{
fill_rubriekselector("D", -1 , data.parents.D);
fill_rubriekselector("P", data.parents.D, data.parents.P);
fill_rubriekselector("R", data.parents.P, data.parents.R);
fill_rubriekselector("G", data.parents.R, data.parents.G);
fill_rubriekselector("S", data.parents.G, data.parents.S);
}
function re_init_plaats(data)
{
var init_key = ($("#account").val() != -1 ? $("#account").val() : data.parents.K);
var project_key = $("#budgetproject").val() || data.parents.P;
fill_plaatsselector("KP", project_key, init_key);
}
function change_discipline()
{
var discipline_key = $("#budgetdiscipline").val();
process_info({niveau:"R",lov:[]});
process_info({niveau:"G",lov:[]});
process_info({niveau:"S",lov:[]});
fill_rubriekselector("P", discipline_key);
$("#account").empty().prop("disabled", true);
use_contingency(false);
$("#order").empty().prop("disabled", true);
}
function change_project()
{
var project_key = $("#budgetproject").val();
process_info({niveau:"G",lov:[]});
process_info({niveau:"S",lov:[]});
fill_rubriekselector("R", project_key);
fill_plaatsselector("KP", project_key);
use_contingency(false);
$("#order").empty().prop("disabled", true);
}
function change_rubriek()
{
var rubriek_key = $("#budgetcostcategory").val();
process_info({niveau:"S",lov:[]});
fill_rubriekselector("G", rubriek_key);
use_contingency(true);
$("#order").empty().prop("disabled", true);
}
function change_groep()
{
var groep_key = $("#costtypegroup").val();
fill_rubriekselector("S", groep_key);
use_contingency(false);
fill_opdrachtselector("OP", groep_key);
}
function change_soort()
{
var project_key = $("#budgetproject").val();
var kplaats_key = -1;
var btw_perc = 0;
if ($("#costtype").val() != -1 )
{
kplaats_key = $("#costtype option:selected").attr("kpn_key");
btw_perc = parseFloat($("#costtype option:selected").attr("perc_btw").replace(/,/g,"."));
}
fill_plaatsselector("KP", project_key, kplaats_key);
if ($("#amount").val() && btw_perc != kostensoort_btw)
{
FcltMgr.confirm(L("bgt_confirm_recalc_vat"), function() { change_amount(); } );
}
use_contingency(false);
}
function change_amount()
{
// bereken btwbedrag (vat) adhv btw-percentage bij kostensoort.
var btw_incl;
var btw_perc;
var amount = parseFloat($("#amount").val().replace(/,/g,"."));
// voor model_mld_opdr en model_bgt_budget
if (btw_data && btw_data.btw_val)
{
btw_incl = btw_data.btw_inc;
btw_perc = parseFloat(btw_data.btw_val);
}
else
{
btw_incl = $("#costtype option:selected").attr("incl_btw") == "1";
btw_perc = parseFloat($("#costtype option:selected").attr("perc_btw").replace(/,/g,"."));
}
kostensoort_btw = btw_perc; // Huidige btw-percentage globaal opslaan.
if (isNaN(amount))
{
$("#vat").val("");
$("#vat").closest("tr").next("tr").find("span").text("");
}
else
{
if (btw_perc && !isNaN(btw_perc))
{
var perc = (btw_perc / 100);
var vat = amount * perc;
var incl = amount + vat;
$("#vat").val(num2currEditable(vat));
$("#vat").closest("tr").next("tr").find("span").text(num2currEditable(incl));
}
}
}
function change_vat()
{
// bereken totaalbedrag bij wijziging van het btw-bedrag.
var amount = parseFloat($("#amount").val().replace(/,/g,"."));
var vat = parseFloat($("#vat").val().replace(/,/g,"."));
var incl = (isNaN(amount) ? vat : amount + vat);
if (isNaN(vat))
{
$("#vat").closest("tr").next("tr").find("span").text("");
}
else
{
$("#vat").closest("tr").next("tr").find("span").text(num2currEditable(incl));
}
}
function change_account()
{
// Vul de prs_kostenplaatsgrp_key
var costgrp_key = $("#account option:selected").attr("par_key");
$("#costgroup").val(costgrp_key);
}
function fill_opdrachtselector(niveau, parent_key, init_key)
{
$.getJSON( "../bgt/get_bgt_info_ajax.asp",
{ req_info: "order",
niveau: niveau,
parent_key: parent_key,
init_key: init_key
},
process_info);
}
function fill_rubriekselector(niveau, parent_key, init_key)
{
var sel_mode = (typeof cur_mode == "undefined" ? "list" : cur_mode);
$.getJSON( "../bgt/get_bgt_info_ajax.asp",
{ req_info: "projectsearch",
niveau: niveau,
parent_key: parent_key,
init_key: init_key,
sel_mode: sel_mode
},
process_info);
}
function fill_plaatsselector(niveau, parent_key, init_key)
{
$("#account").prop("disabled", false);
$.getJSON( "../bgt/get_bgt_info_ajax.asp",
{ req_info: "plaatssearch",
niveau: niveau,
parent_key: parent_key,
init_key: (init_key ? init_key : -1)
},
process_info);
}
function use_contingency(contingency_mode)
{
if (contingency_mode)
{
$("input#contingency").prop("disabled", false );
}
else
{
$("input#contingency").prop('checked', false);
$("input#contingency").prop("disabled", true );
}
}
function process_info(data)
{
var select;
switch(data.niveau)
{
case "D": select = $("#budgetdiscipline"); break;
case "P": select = $("#budgetproject"); break;
case "R": select = $("#budgetcostcategory"); break;
case "G": select = $("#costtypegroup"); break;
case "S": select = $("#costtype"); break;
case "KP": select = $("#account"); break;
case "OP": select = $("#order"); break;
}
var add_data = "";
var sel_key = -1;
var new_lov = '<option value="-1" ></option>';
if (data.lov.length > 0)
{
for (i=0; i < data.lov.length;i++)
{
var opt = data.lov[i];
if (data.niveau == "KP")
{
add_data = ' par_key="' + opt.atr.par_key + '"'
+ ' kpn_key="' + opt.atr.kpn_key + '"';
}
else
{
add_data = ' incl_btw="' + opt.atr.btw_inc + '"'
+ ' perc_btw="' + opt.atr.btw_val + '"'
+ ' kpn_key="' + opt.atr.kpn_key + '"';
}
new_lov += '<option value="' + opt.key + '"' + (opt.sel?" selected":"") + add_data + '>'+ opt.oms + '</option>';
if (opt.sel)
sel_key = opt.key;
}
select.prop("disabled", false);
}
else
{
select.prop("disabled", true);
}
select.empty().append(new_lov);
if (sel_key > -1)
select.val(sel_key);
$("input#contingency").prop("disabled", true );
}