<% /*
    $Revision$
    $Id$

    File:           model_fin_kenmerk.inc

    Description:    Vanuit CodeCharge gegenereerd model voor fin_kenmerk

    Context:

    Notes:
*/
%>
<%

function model_fin_kenmerk(niveau, params)
{
    params = params || {};
    this.records_name = "invoiceproperties";
    this.record_name = "invoiceproperty";
    this.table = "fin_kenmerk";
    this.primary = "fin_kenmerk_key";
    this.soft_delete = "fin_kenmerk_verwijder";
    this.autfunction = params.internal? false : "WEB_FINMGT";
    this.record_title = L("fin_kenmerk")    + " " + get_fin_type_name(niveau); // dit niveau lijkt niet te werken?
    this.records_title = L("fin_kenmerk_m") + " " + get_fin_type_name(niveau);
    this.module = "FIN";

    this.fields = {
        "id": {
            "dbs": "fin_kenmerk_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "fin_s_fin_kenmerk_key"
        },
        "sequence": {
            "dbs": "fin_kenmerk_volgnr",
            "label": L("mgt_kenmerk_volgnummer"),
            "typ": "number",
            "len": 3,
            "required": true
        },
        "name": {
            "dbs": "fin_kenmerk_omschrijving",
            "label": L("mgt_kenmerk_omschrijving"),
            "typ": "varchar",
            "translate": true,
            "required": true
        },
        "hint": {
            "dbs": "fin_kenmerk_hint",
            "label": L("mgt_kenmerk_hint"),
            "typ": "memo",
            "translate": true
        },
        "unit": {
            "dbs": "fin_kenmerk_dimensie",
            "label": L("mgt_srtkenmerk_dimensie"),
            "typ": "varchar",
            "translate": true
        },
        "attributetype": {
            "dbs": "fin_kenmerk_kenmerktype",
            "label": L("mgt_srtkenmerk_kenmerktype"),
            "typ": "varchar",
            "required": true,
            "LOV": buildKenmerktypeLOV(),
            "showtransit": true
        },
        "propertytype": {
            "dbs": "fin_kenmerk_type",
            "label": L("fin_kenmerk_type"),
            "typ": "varchar",
            "LOV": fill_fin_type_LOV(),
            "emptyoption": null
        },
        "rolecode": {  // heeft voor deze module nog geen werking
            "dbs": "fin_kenmerk_rolcode",
            "label": L("mgt_kenmerk_rolcode"),
            "typ": "number",
            "LOV": buildKenmerkRoleCodeLOV({ module: "FIN" }),
            "required": true
        },
        "required": {
            "dbs": "fin_kenmerk_verplicht",
            "label": L("mgt_kenmerk_verplicht"),
            "typ": "key",
            "LOV": buildVerplichtingList(),
            "emptyisrealvalue": true,
            "emptyoption": null
        },
        "group": {
            "dbs": "fin_kenmerk_groep",
            "label": L("mgt_kenmerk_groep"),
            "typ": "key",
            "required": true,
            "LOV": buildGroepsverplichtingList(),
            "emptyoption": null
        },
        "readonly": {
            "dbs": "fin_kenmerk_toonbaar",
            "label": L("mgt_kenmerk_toonbaar"),
            "typ": "check"
        },
        "system": {
            "dbs": "fin_kenmerk_systeem",
            "label": L("mgt_srtkenmerk_systeem_adv"),
            "typ": "number",
            "bits": [
                {
                    "name": "",
                    "label": "",
                    "showasgroup": false,
                    "typ": "check",
                    "mask": 15,
                    "radios": [
                        {
                            "name": "ksystem",
                            "label": L("mgt_kenmerk_systeem"),
                            "mask": 1,
                            "defaultvalue": 0
                        },
                        // {
                        //     "name": "conf",
                        //     "label": L("mgt_kenmerk_systeem_conf"),
                        //     "mask": 4,
                        //     "defaultvalue": 0
                        // },
                        {
                            "name": "ano",
                            "label": L("mgt_kenmerk_systeem_ano"),
                            "mask": 8,
                            "defaultvalue": 0
                        }
                    ]
                }
            ],
            "defaultvalue": 0,
            "required": true
        },
        "inlist": {
            "dbs": "fin_kenmerk_inlijst",
            "label": L("mgt_kenmerk_systeem_overview"),
            "typ": "check0",
            "multiedit": true
        },
        "length": {
            "dbs": "fin_kenmerk_lengte",
            "label": L("mgt_srtkenmerk_lengte"),
            "typ": "number"
        },
        "decimals": {
            "dbs": "fin_kenmerk_dec",
            "label": L("mgt_srtkenmerk_dec"),
            "typ": "number"
        },
        "minimum": {
            "dbs": "fin_kenmerk_nmin",
            "label": L("mgt_srtkenmerk_nmin"),
            "typ": "number"
        },
        "maximum": {
            "dbs": "fin_kenmerk_nmax",
            "label": L("mgt_srtkenmerk_nmax"),
            "typ": "number"
        },
        "domain": {
            "dbs": "fac_kenmerkdomein_key",
            "label": L("fac_kenmerkdomein_key"),
            "typ": "key",
            "foreign": fac_kenmerkdomein_foreign("FIN"),
            "LOVinit": ""
        },
        "propertydefault": {
            "dbs": "fin_kenmerk_default",
            "label": L("mgt_kenmerk_default"),
            "typ": "memo",
            "translate": true
        },
        "showexpression": {
            "dbs": "fin_kenmerk_show_expr",
            "label": L("mgt_kenmerk_show_expr"),
            "typ": "memo"
        },
        "regexp": {
            "dbs": "fin_kenmerk_regexp",
            "label": L("mgt_kenmerk_regexp"),
            "typ": "varchar"
        },
        "code": {
            "dbs": "fin_kenmerk_code",
            "label": L("mgt_kenmerk_code"),
            "typ": "varchar",
            "readonly": !user.has("WEB_PRSSYS")
        },
        "authorization": {
            "dbs": "fac_functie_key",
            "label": L("mgt_kenmerk_autorisatie"),
            "typ": "key",
            "foreign": "fac_functie"
        }
    };


    this.hook_pre_show = function (obj, fld)
    {
        fld.propertydefault.label = (obj.attributetype.id == "l" ? L("mgt_kenmerk_icon"): L("mgt_kenmerk_default"));
        fld.readonly.label = (obj.attributetype.id == "l" ? L("mgt_kenmerk_collapsed"): L("mgt_kenmerk_toonbaar"));
    }

    this.hook_pre_edit = function (obj, fld)
    {
        var kenmerktype = (obj.attributetype ? obj.attributetype.id : "");
        fld.attributetype.LOV = buildKenmerktypeLOV(kenmerktype);
        fld.propertydefault.label = ( (obj.id == -1 && obj.attributetype == "l") || (obj.attributetype && obj.attributetype.id == "l") ? L("mgt_kenmerk_icon"): L("mgt_kenmerk_default") );
        fld.readonly.label = ( (obj.id == -1 && obj.attributetype == "l") || (obj.attributetype && obj.attributetype.id == "l") ? L("mgt_kenmerk_collapsed"): L("mgt_kenmerk_toonbaar") );
    %>
    <script type="text/javascript">
      var module = "FIN";
      var property_type = "<%=safe.jsstring(kenmerktype)%>";
    </script>
    <%
    }

    var gparams = {"GET": {}};
    if (niveau)
    {
        gparams.GET = { wheres: [ "fin_kenmerk.fin_kenmerk_type = " + safe.quoted_sql(niveau) ] };
    }

    this.REST_GET    = generic_REST_GET(this);
    this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this);

    function fill_fin_type_LOV()
    {
        return  "F;"+L("fin_invoice")
             + ";R;"+L("fin_invoicerows");
    }

    function get_fin_type_name(niveau)
    {
        var naam = "";
        switch (niveau)
        {
            case "F": naam = L("fin_invoice"); break;
            case "R": naam = L("fin_invoicerows"); break;
        }
        return naam;
    }
}
%>