<% /*
    $Revision$
    $Id$

    File:           model_bes_kenmerk.inc

    Description:    Vanuit CodeCharge gegenereerd model voor bes_kenmerk

    Context:

    Notes:
*/
%>
<%

function model_bes_kenmerk()
{
    this.table = "bes_kenmerk";
    this.primary = "bes_kenmerk_key";
    this.records_name = "bes_kenmerks";
    this.record_name = "bes_kenmerk";
    this.soft_delete = "bes_kenmerk_verwijder";
    this.autfunction = "WEB_BESMGT";
    this.record_title = L("bes_kenmerk");
    this.records_title = L("bes_kenmerk_m");


    this.fields = {
        "id": {
            "dbs": "bes_kenmerk_key",
            "label": "Key",
            "typ": "key",
            "required": true,
            "filter": "exact",
            "seq": "bes_s_bes_kenmerk_key",
            "defaultvalue": null
        },
        "catalogue_key": {
            "dbs": "bes_srtinstallatie_key",
            "label": "bes_srtinstallatie_key",
            "typ": "key",
            "hidden_fld": true,
            "foreign": {
                "tbl": "bes_v_aanwezigdiscipline",
                "key": "ins_discipline_key",
                "desc": "ins_discipline_omschrijving"
            },
            "filter": "exact"
        },
        "property_key": {
            "dbs": "bes_srtkenmerk_key",
            "label": L("mgt_srtkenmerk_key"),
            "typ": "key",
            "required": true,
            "insertonly": true,
            "foreign": {
                "tbl": "(select bes_srtkenmerk_key"
                     + "      , bes_srtkenmerk_omschrijving"
                     + "   from bes_srtkenmerk"
                     + "  where bes_srtkenmerk_verwijder is null"
                     + "  order by bes_srtkenmerk_omschrijving asc)",
                "key": "bes_srtkenmerk_key",
                "desc": "bes_srtkenmerk_omschrijving"
            },
            "filter": "exact",
            "defaultvalue": null,
            "LOVinit": "",
            "friendlyname": true
        },
        "article_catalogue": {
            "dbs": "bes_kenmerkbestelregel.ins_discipline_key",
            "label": L("bes_ins_discipline_key"),
            "typ": "key",
            "required": true,
            "insertonly": true,
            "foreign": {
                "tbl": "bes_v_aanwezigdiscipline",
                "key": "ins_discipline_key",
                "desc": "ins_discipline_omschrijving"
            }
        },
        "article_group": {
            "dbs": "bes_kenmerkbestelregel.bes_srtgroep_key",
            "label": L("bes_srtgroep"),
            "typ": "key",
            "insertonly": true,
            "foreign": {
                "tbl": "bes_srtgroep",
                "key": "bes_srtgroep_key",
                "desc": "bes_srtgroep_omschrijving"
            }
        },
        "article": {
            "dbs": "bes_kenmerkbestelregel.bes_srtdeel_key",
            "label": L("bes_srtdeel"),
            "typ": "key",
            "insertonly": true,
            "foreign": {
                "tbl": "bes_srtdeel",
                "key": "bes_srtdeel_key",
                "desc": "bes_srtdeel_omschrijving"
            }
        },
        "level": {
            "dbs": "bes_kenmerk_niveau",
            "label": L("mgt_kenmerk_niveau"),
            "typ": "varchar",
            "hidden_fld": true,
            "LOV": buildBESKenmerkNiveauList(),
            "emptyoption": null,
            "defaultvalue": "D"
        },
        "order_type": {
            "dbs": "bes_kenmerk_type",
            "label": L("bes_kenmerk_type"),
            "typ": "varchar",
            "hidden_fld": true,
            "defaultvalue": "I"
        },
        "sequence": {
            "dbs": "bes_kenmerk_volgnummer",
            "label": L("mgt_kenmerk_volgnummer"),
            "typ": "number",
            "required": true
        },
        "property_required": {
            "dbs": "bes_kenmerk_verplicht",
            "label": L("mgt_kenmerk_verplicht"),
            "typ": "key",
            "LOV": buildVerplichtingList(),
            "emptyoption": null
        },
        "property_group": {
            "dbs": "bes_kenmerk_groep",
            "label": L("mgt_kenmerk_groep"),
            "typ": "key",
            "required": true,
            "LOV": buildGroepsverplichtingList(),
            "emptyoption": null
        },
        "property_readonly": {
            "dbs": "bes_kenmerk_toonbaar",
            "label": L("mgt_kenmerk_toonbaar"),
            "typ": "check"
        },
        "property_default": {
            "dbs": "bes_kenmerk_default",
            "label": L("mgt_kenmerk_default"),
            "typ": "memo",
            "translate": true
        },
        "property_hint": {
            "dbs": "bes_kenmerk_hint",
            "label": L("mgt_kenmerk_hint"),
            "typ": "varchar",
            "translate": true,
            "filter": "like",
            "defaultvalue": null
        },
        "property_regexp": {
            "dbs": "bes_kenmerk_regexp",
            "label": L("mgt_kenmerk_regexp"),
            "typ": "varchar"
        }
    };


    var ext_sql = "(SELECT DISTINCT"
                + "        B.bes_kenmerk_key"
                + "      , S.bes_srtkenmerk_omschrijving"
                + "      , B.bes_kenmerk_volgnummer"
                + "      , B.bes_kenmerk_niveau"
                + "      , B.bes_kenmerk_type"
                + "      , B.bes_srtinstallatie_key"
                + "      , B.bes_srtkenmerk_key"
                + "      , B.bes_kenmerk_hint"
                + "      , S.bes_srtkenmerk_key"
                + "      , I.bes_discipline_key ins_discipline_key" //I.ins_discipline_key
                + "      , CASE WHEN b.bes_kenmerk_niveau <> 'D' THEN I.bes_srtgroep_key END bes_srtgroep_key"
                + "      , CASE WHEN b.bes_kenmerk_niveau = 'S'  THEN I.bes_srtdeel_key  END bes_srtdeel_key"
                + "   FROM bes_kenmerk B"
                + "      , bes_srtkenmerk S"
                + "      , BES_V_ALLSRTINSTALLATIE I"
                + "  WHERE B.bes_srtkenmerk_key = S.bes_srtkenmerk_key"
                + "    AND B.bes_kenmerk_type = 'I'"
                + "    AND S.bes_srtkenmerk_verwijder IS NULL"
                + "    AND B.bes_srtinstallatie_key = I.bes_srtinstallatie_key"
                + "    AND B.bes_kenmerk_niveau = I.niveau"
                + ") bes_kenmerkbestelregel";


    this.REST_GET    = generic_REST_GET(this, {
        "GET": {
            "tables": [ ext_sql],
            "wheres": [ "bes_kenmerk.bes_kenmerk_key = bes_kenmerkbestelregel.bes_kenmerk_key" ]
        }
    });

    this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this, {});
}
%>