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

    File:           mgt_generic.asp

    Description:    Ingang om generiek tabel data te bekijken
    Context:        Vanuit user_tables.asp

    Notes:          Alleen voor FACFAC
                    Vooralsnog geforceerd readonly
*/
%>

<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../api2/model_generic.inc" -->

<%
    user.checkAutorisation("WEB_FACFAC");

    var edit_fields = { "bes_bestelopdr":  { "track": null,
                                             "fields": ["bes_bestelopdr_status"]
                                           },
                        "cnt_contract":    { "track": "#CNTUPD",
                                             "fields": ["cnt_contract_status",
                                                        "ins_discipline_key",
                                                        "cnt_contract_teverzenden"]
                                           },
                        "fac_tracking":    { "track": null,
                                             "fields": ["fac_tracking_datum",
                                                        "name",
                                                        "fac_tracking_oms",
                                                        "prs_perslid_key"]
                                           },
                        "fac_activiteit":  { "track": null,
                                             "fields": ["fac_activiteit_volgende",
                                                        "fac_activiteit_laatste",
                                                        "fac_activiteit_periode",
                                                        "fac_activiteit_eenheid",
                                                        "prs_perslid_key"]
                                           },
                        "fac_faq":         { "track": null,
                                             "fields": ["fac_faq_level",
                                                        "fac_faq_datum",
                                                        "fac_faq_vervaldatum",
                                                        "fac_faq_displaymode",
                                                        "faq_ins_discipline_key"]
                                           },
                        "ins_deelsrtcontrole": { "track": "#INSCUP",
                                                 "fields": ["ins_deelsrtcontrole_status",
                                                            "ins_deelsrtcontrole_plandatum",
                                                            "ins_deelsrtcontrole_datum",
                                                            "ins_deelsrtcontrole_datum_org",
                                                            "ins_controlemode_key",
                                                            "ins_deelsrtcontrole_opmerking",
                                                            "ins_deelsrtcontrole_freezecost"]
                                               },
                        "ins_srtcontroledl_xcp": { //"track": "#INSUPD", // Geen tracking omdat deze dan niet bij het object (ins_deel) wordt getrackt.
                                                   "fields": ["ins_srtcontroledl_xcp_periode"]
                                                 },
                        "fin_factuur":     { "track": "#FINUPD",
                                             "fields": ["prs_kostensoort_key",
                                                        "fin_factuur_statuses_key",
                                                        "fin_factuur_boekmaand",
                                                        "mld_opdr_key",
                                                        "cnt_contract_key",
                                                        "bes_bestelopdr_key"]
                                           },
                        "fin_verkoopfactuur":
                                           { "track": null,
                                             "fields": ["fin_verkoopfactuur_maand",
                                                        "fin_verkoopfactuur_bedrag",
                                                        "fin_verkoopfactuur_n3"]
                                           },
                        "mld_melding":     { "track": "#MLDUPD",
                                             "fields": ["mld_melding_status",
                                                        "prs_perslid_key",
                                                        "prs_kostenplaats_key",
                                                        "mld_melding_start_key",
                                                        "mld_melding_kto_key",
                                                        "mld_melding_kto_type"]
                                           },
                        "mld_opdr":        { "track": "#ORDUPD",
                                             "fields": ["mld_typeopdr_key",
                                                        "mld_statusopdr_key",
                                                        "mld_uitvoerende_keys",
                                                        "mld_opdr_teverzenden",
                                                        "mld_opdr_verzonden",
                                                        "prs_kostenplaats_key",
                                                        "mld_opdr_einddatum",
                                                        "mld_opdr_discipline_key"]
                                           },
                        "res_rsv_ruimte":  { "track": "#RESUPD",
                                             "fields": ["res_status_fo_key",
                                                        "res_status_bo_key",
                                                        "res_rsv_ruimte_externsyncdate"]
                                           },
                        "res_rsv_deel":    { "track": "#RESUPD",
                                             "fields": ["res_status_bo_key"]
                                           },
                        "res_rsv_artikel": { "track": "#RESUPD",
                                             "fields": ["res_status_bo_key"]
                                           },
                        "cnt_disc_params": { "track": null,
                                             "fields": ["cnt_srtcontract_type"]
                                           },
                        "fac_usrrap":      { "track": null,
                                             "fields": ["fac_usrrap_functie",
											            "fac_usrrap_vraagbegindatum",
														"fac_usrrap_vraageinddatum"]
                                           },
                        "mld_stdmelding":  { "track": null,
                                             "fields": ["mld_stdmelding_freetext"]
                                           },
                        "bes_bestelling":  { "track": "#BESUPD",
                                             "fields": ["prs_kostenplaats_key",
                                                        "bes_bestelling_status",
                                                        "prs_perslid_key_voor"]
                                           },
                        "ins_deel":        { "track": "#INSUPD",
                                             "fields": ["ins_srtdeel_key",
                                                        "ins_alg_ruimte_key",
                                                        "ins_alg_ruimte_type",
                                                        "ins_alg_ruimte_type_org",
                                                        "ins_alg_ruimte_key_org",
                                                        "ins_deel_dwgx",
                                                        "ins_deel_dwgy"]
                                           },
                        "mld_melding_note": { "track": null,
                                             "fields": ["name", "mld_melding_note_flag"]
                                           },
                        "ins_srtdeel": { "track": "#INSSUP",
                                             "fields": ["ins_srtdeel_omschrijving",
                                                        "ins_srtdeel_mjb_grensscore1",
                                                        "ins_srtdeel_acadsymbol",
                                                        "ins_srtgroep_key"]
                                           },
                        "mld_kenmerk": {
                                             "fields": ["mld_srtkenmerk_key"]
                                           },
                        "mld_melding_object": {
                                             "fields": ["ins_deel_key"]
                                           },
                        "prs_perslid":     { "track": "#PRSUPD",
                                             "fields": ["prs_perslid_lang",
                                                        "prs_perslid_flags",
                                                        "prs_perslid_inactief",
                                                        "prs_perslid_key_verantw",
                                                        "prs_perslid_mobiel"]
                                           },
                        "fac_bookmark":    { "track": null,
                                             "fields": ["fac_bookmark_id"]
                                           },
                        "prs_bedrijfadres": { "track": "#PRSUPT",
                                             "fields": ["prs_bedrijfadres_type",
                                                        "prs_bedrijfadres_template",
                                                        "prs_bedrijfadres_attachfile",
                                                        "prs_bedrijfadres_loglevel"]
                                           },
                        "prs_bedrijf":     { "track": "#PRSUPB",
                                             "fields": ["prs_bedrijf_naam",
                                                        "prs_bedrijf_intern"]
                                           },
                        "fac_version":     { "fields": ["fac_version_cust",
                                                        "fac_version_group",
                                                        "fac_version_lang",
                                                        "fac_version_otap"]
                                           },
                        "alg_ruimte":      { "track": "#ALGRUP",
                                            "fields": ["alg_verdieping_key"]
                                           },
                        "fac_menu":        { "track": null,
                                            "fields": ["fac_menu_alturl",
                                                       "fac_menu_volgnr",
                                                       "fac_menu_filter"]
                                           },
                        "ins_srtkenmerk":  { "track": null,
                                            "fields": ["ins_srtkenmerk_kenmerktype"]
                                           },
                        "cnt_kenmerk":     { "track": null,
                                            "fields": ["cnt_kenmerk_niveau"]
                                           }
                      }

    var table = getQParam("table").toUpperCase();

    var model = model_generic(table, "WEB_FACFAC");

    var params = { "transit": { "table": table  },
                   "show": {} // zodat je kunt doorklikken
                 };

    // Meeste velden geforceerd readonly
    for (var fld in model.fields)
    {
        var field = model.fields[fld];
        var exception = edit_fields[table.toLowerCase()];
        if (fld == "prs_perslid_key_verantw")
            field.foreign = "PRS_PERSLID";
        if (fld == model.soft_delete ||
            fld.match(/externsyncdate$/) ||
            fld.match(/extsyncdate$/) ||
            fld.match(/extsyncd$/) ||
            fld.match(/externnr2?$/) ||
            fld.match(/externid$/) ||
            exception && inArray(fld, exception.fields))
        {
            field.multiedit = true; // alle gedefinieerde edit_fields velden.
            if (field.foreign && typeof field.foreign == "string" &&
                inArray(field.foreign, ["ins_srtdeel"])) // die gaat wel goed
            {
                field.multiedit = true
            }
            field.track = true;
            if (mode == "save" && field.typ == "key" && !("foreign" in field))
            {
                field.foreign = function (x) { return String(x) };
            }
            field.track = true;
            model.trackcode = exception && exception.track;

            if (mode == "edit" && (fld == "alg_verdieping_key" || fld == "cnt_contract_key" || fld == "mld_opdr_key")) // Scaffolding.inc genereert geen selector voor verdiepingen enz en maakt hem zelfs readonly
                field.foreign = null;

            continue;
        }
        // Anders altijd:
        field.readonly = true;
    }

    if (mode == "show" || mode == "edit" )
        delete model.soft_delete;

    params.search = {};
    if ("id" in model.fields)
    {
        params.search.labels = [{ "lbl": "Primary key", "txt" : "{0}".format(model.fields["id"].dbs)}];
        if (model.fields["id"].seq)
        {
            var sql = "SELECT last_number currval"
                    + "  FROM user_sequences"
                    + " WHERE sequence_name = " + safe.quoted_sql_upper(model.fields["id"].seq);
            var oRs = Oracle.Execute(sql)
            var curval = oRs(0).Value;
            oRs.Close();
            params.search.labels.push({ "lbl": "Sequence", "txt" : "{0} (next: {1})".format(model.fields["id"].seq, curval)});
        }
    }
    else // geen id. Dan kun je niet doorklikken. Toon dan maar alle kolommen
    {
        params.search.labels = [{ "lbl": "Primary key", "txt" : "No single NUMBER primary key detected. Record clicking not available."}];
        params.list = { columns : [] };
        for (var fld in model.fields)
        {
            params.list.columns.push(fld);
        }
    }

    if ("estimated_rows" in model && model.estimated_rows < S("qp_maxrows"))
        params.search.autosearch = true;


    if (getQParamInt("scf_multi", 0) == 0 && model.nrfields > 10) {
        params.multicolumn = true;
        params.layout = {
            "block": [{
                "icon": "fa-database"
            }, {
                "icon": "fa-database"
            }]
        }
    } else {
        params.layout = {
            "miscellaneous": {
                "icon": "fa-database"
            }
        }
    }

    var orderby = getQParamSafe("scf_orderby", "");
    if (orderby && orderby in model.fields)
        model.gparams.GET.orderbys = [orderby];

    // Toevoegen en delete staan we niet toe
    model.REST_POST   = null;
    model.REST_DELETE = null;

    scaffolding(model, params);
%>
<% ASPPAGE_END(); %>
