<% /*
    $Revision$
    $Id$

    File:           model_fac_usrdata.inc

    Description:    Vanuit CodeCharge gegenereerd model voor fac_usrdata

    Context:

    Notes:
*/
%>
<%
function model_fac_usrdata()
{
    var tab_key = getQParamInt("usertable", -1);

    this.table = "fac_usrdata"
    this.primary = "fac_usrdata_key";
    this.records_name = "fac_usrdatas";
    this.record_name = "fac_usrdata";
    this.soft_delete = "fac_usrdata_verwijder";
    this.record_title = L("fac_usrdata");
    this.records_title = L("fac_usrdata_m");


    this.fields = {
        "id": {
            "dbs": "fac_usrdata_key",
            "label": "Key",
            "typ": "key",
            "required": true,
            "filter": "exact",
            "seq": "fac_s_fac_usrdata_key"
        },
        "usertable": {
            "dbs": "fac_usrtab_key",
            "label": L("fac_usrtab_naam"),
            "typ": "key",
            "hidden_fld": true,
            "required": true
        },
        "name": {
            "dbs": "fac_usrdata_code",
            "label": L("fac_usrdata_code"),
            "typ": "varchar",
            "required": true
        },
        "description": {
            "dbs": "fac_usrdata_omschr",
            "label": L("fac_usrdata_omschr"),
            "typ": "varchar",
            "translate": true
        },
        "sequence": {
            "dbs": "fac_usrdata_volgnr",
            "label": L("fac_usrdata_volgnr"),
            "typ": "number"
        },
        "price": {
            "dbs": "fac_usrdata_prijs",
            "label": L("fac_usrdata_prijs"),
            "iscurrency": true,
            "typ": "float"
        },
        "expirationdate": {
            "dbs": "fac_usrdata_vervaldatum",
            "label": L("fac_usrdata_vervaldatum"),
            "typ": "date",
            "autosize": true
        },
        "reftable": {
            "dbs": "fac_usrdata_parentkey",
            "label": L("fac_usrdata_parentkey"),
            "typ": "key",
            "foreign": {
                "tbl": "fac_usrdata",
                "key": "fac_usrdata_key",
                "desc": "fac_usrdata_omschr"
            }
        }
    },


    this.list = {
        "columns": [
            "id",
            "description",
            "name",
            "sequence",
            "price",
            "expirationdate"
        ]
    };
    this.search = {
        "autosearch": true
    };
    this.edit = {
        "modal": true
    };

    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, {});

    // Server side code!
    //
    if (tab_key > 0)
    {
        // Autorisatie
        var authparams = user.checkAutorisation("WEB_PRSSYS", true);
        if (!authparams)
        {
            var sql = "SELECT fac_functie_key"
                    + "  FROM fac_usrtab"
                    + " WHERE fac_usrtab_key = " + tab_key;
            var oRs = Oracle.Execute(sql);
            this.autfunction = oRs("fac_functie_key").Value || "WEB_PRSSYS";
            oRs.Close();
        }
        else
            this.autfunction = authparams.autfunction;

        // Referentie tabel
        var sql = "SELECT C.fac_usrtab_parentkey"
                + "     , P.fac_usrtab_omschrijving"
                + "  FROM fac_usrtab P"
                + "     , fac_usrtab C"
                + " WHERE C.fac_usrtab_key = " + tab_key
                + "   AND P.fac_usrtab_key = C.fac_usrtab_parentkey";
        var oRs = Oracle.Execute(sql);
        if (!oRs.Eof)
        {
            this.fields.reftable.foreign.where = " fac_usrtab_key = " + oRs("fac_usrtab_parentkey").Value;
            this.fields.reftable.label = oRs("fac_usrtab_omschrijving").Value;
        }
        else
            delete this.fields.reftable;
        oRs.Close();
    }
    else
        delete this.fields.reftable;
}
%>