<% /*
    $Revision$
    $Id$

    File:           model_reservableconsumables.inc

    Description:    reserveerbare artikelen model.
    Parameters:
    Context:

    Notes:
*/

%>
<!-- #include file="../Shared/discxalg3d.inc"-->
<%

model_reservableconsumables =
{
    table: "res_artikel",
    primary: "res_artikel_key",
    records_name: "reservableconsumables",
    record_name: "reservableconsumables",
    fields: { "id"          : { dbs: "res_artikel_key",             typ: "key",     filter: "exact" },
              "name"        : { dbs: "res_artikel_omschrijving",    typ: "varchar", filter: "like"  },
              "code"        : { dbs: "res_artikel_nr",              typ: "number",  filter: "like"  },
              "sequence"    : { dbs: "res_artikel_volgnummer",      typ: "number" },
              "remark"      : { dbs: "res_artikel_opmerking",       typ: "varchar", filter: "like"  },
              "unit"        : { dbs: "res_artikel_eenheid",         typ: "varchar", filter: "like"  },
              "price"       : { dbs: "res_artikel_prijs",           typ: "float",   "iscurrency": true  },
              "fixed"       : { dbs: "res_artikel_prijs_vast",      typ: "check0",  filter: "exact" },
              "purchase"    : { dbs: "res_artikel_inkoopprijs",     typ: "float",   "iscurrency": true},
              "vat"         : { dbs: "res_artikel_btw",             typ: "float" },
              "employeecost": { dbs: "res_artikel_kostenpersoneel", typ: "float",   "iscurrency": true },
              "generalcost" : { dbs: "res_artikel_kostenalgemeen",  typ: "float",   "iscurrency": true },
              "catalog"     : { dbs: "res_discipline_key",          typ: "key",     foreign: "res_discipline" },
              "group"       : { dbs: "res_artikel_groep",           typ: "varchar", filter: "like" },
              "start"       : { dbs: "res_artikel_ingangsdatum",    typ: "date" },
              "expires"     : { dbs: "res_artikel_vervaldatum",     typ: "date" },
              "minimum"     : { dbs: "res_artikel_minimum",         typ: "number",  filter: "exact" }
             },

    REST_GET: function _GET(params)
        {
            var urole = "fe"; // TODO: Moet echt niet ter zake doen
            var autfunction = urole == "fe"? "WEB_RESUSE" : "WEB_RESMAN";
            params.authparams = user.checkAutorisation(autfunction, null, null, true); // pessimistisch

            // TODO: Add authorization
            var query = api2.sqlfields(params, model_reservableconsumables);
            query.wheres.push("res_artikel_verwijder IS NULL");

            var wheres = api2.sqlfilter(params, model_reservableconsumables);
            query.wheres = query.wheres.concat(wheres);

            var sql = "SELECT " + query.selects.join(", ")
                    + "  FROM " + query.tables.join(", ")
                    + " WHERE " + query.wheres.join(" AND " )
                    + " ORDER BY res_artikel_omschrijving";
            var json = api2.sql2json (params, sql, model_reservableconsumables);
            return json;
        },
    PUT: function (params) /* update reservable articles */
    {
    },
    POST: function (params) /* new reservable article */
    {
    },
    DELETE: function (params) /* delete reservable article */
    {
    }
}
%>
