<% /*
    $Revision$
    $Id$

    File:           model_bes_bestelopdr_item.inc

    Description:    model voor bes_bestelopdr_item

    Context:

    Notes:
*/
%>
<!-- #include file="../BES/bes.inc" -->
<%

function model_bes_bestelopdr_item()
{
    this.records_name = "purchaseorderitems";
    this.record_name = "purchaseorderitem";
    this.table = "bes_bestelopdr_item";
    this.primary = "bes_bestelopdr_item_key";
    this.autfunction = null;
    this.record_title = L("lcl_bes_bestelopdracht");
    this.records_title = L("lcl_bes_bestelling_orders");

    this.fields = {
        "id": {
            "dbs": "bes_bestelopdr_item_key",
            "seq": "bes_s_bes_bestelopdr_item_key",
            "typ": "key",
            "label": L("lcl_key"),
            "required": true
        },
        "sequence": {
            "dbs": "bes_bestelopdr_item_posnr",
            "typ": "number",
            "label": "Volgnr" // L("lcl_bes_opdr_volgnr")
        },
        "amount": {
            "dbs": "bes_bestelopdr_item_aantal",
            "typ": "number",
            "label": L("lcl_bes_amount"),
            "required": true
        },
        "received": {
            "dbs": "bes_bestelopdr_item_aantalontv",
            "typ": "number",
            "label": L("lcl_bes_ontvangen")
        },
        "expected": {
            "dbs": "bes_bestelopdr_item_aantalexp",
            "typ": "number",
            "label": L("lcl_bes_opdr_verwacht")
        },
        "description": {
            "dbs": "bes_bestelopdr_item_omschrijv",
            "typ": "memo",
            "label": L("lcl_bes_opdr_omschrijving")
        },
        "itemprice": {
            "dbs": "bes_bestelopdr_item_prijs",
            "typ": "currency",
            "label": L("lcl_bes_price_per_unity")
        },
        "itempurchaseprice": {
            "dbs": "bes_bestelopdr_item_inkprijs",
            "typ": "currency",
            "label": L("lcl_bes_srtdeel_prijs_inkprijs")
        },
        "itemgrossprice": {
            "dbs": "bes_bestelopdr_item_brutoprijs",
            "typ": "currency",
            "label": L("lcl_bes_brutoprijs")
        },
        "received": {
            "dbs": "bes_bestelopdr_item_ontvangen",
            "typ": "datetime",
            "label": L("lcl_bes_ontvangen")
        },
        "status": {
            "dbs": "bes_bestelopdr_item_status",
            "typ": "number",
            "label": L("lcl_bes_Bes_status")
        },
        "closed": {
            "dbs": "bes_bestelopdr_item_verwerkt",
            "typ": "datetime",
            "label": L("lcl_bes_verwerkt")
        },
        "remark": {
            "dbs": "bes_bestelopdr_item_opmerking",
            "typ": "memo",
            "label": L("lcl_bes_item_remark")
        }
    };


    function _check_authorization(params, method)
    {
        var sql = "SELECT bes_bestelopdr_key"
                + "  FROM bes_bestelopdr_item"
                + " WHERE bes_bestelopdr_item_key = " + params.filter.id;
        var oRs = Oracle.Execute(sql);
        var bes_key = oRs("bes_bestelopdr_key").Value;
        switch (method)
        {
            case "GET": var this_bes = bes.func_enabled_bestelopdracht(bes_key);
                        user.auth_required_or_abort(this_bes.canReadAny);
                        break;
        }
        params.func_enabled = this_bes || {};
    };

    this.REST_GET    = function _GET(params, jsondata)
        {
            _check_authorization(params, "GET");

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

            var sql = "SELECT " + query.selects.join(", ")
                    + "  FROM " + query.tables.join(", ");
            if (query.wheres.length)
                sql += " WHERE " + query.wheres.join(" AND " );

            var json = api2.sql2json (params, sql, this );

            return json;
        };
    //this.REST_POST   = generic_REST_POST(this);
    //this.REST_PUT    = generic_REST_PUT(this);
    //this.REST_DELETE = generic_REST_DELETE(this);
}
%>