<% /*
    $Revision$
    $Id$

    File:           model_bes_bestelopdr.inc

    Description:    model voor bes_bestelopdr

    Context:

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

function model_bes_bestelopdr()
{
    this.records_name = "purchaseorders";
    this.record_name = "purchaseorder";
    this.table = "bes_bestelopdr";
    this.primary = "bes_bestelopdr_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_key",
            "seq": "bes_s_bes_bestelopdr_key",
            "typ": "key",
            "label": L("lcl_key"),
            "required": true
        },
        "name": {
            "dbs": "bes_bestelopdr_id",
            "typ": "varchar",
            "label": L("lcl_bes_bestelopdracht")
        },
        "module": {
            "dbs": "bes_bestelopdr_module",
            "typ": "varchar",
            "label": L("lcl_fac_module")
        },
        "status": {
            "dbs": "bes_bestelopdr_status",
            "typ": "number",
            "label": L("lcl_bes_orders_status")
        },
        "supplier": {
            "dbs": "prs_bedrijf_key",
            "typ": "key",
            "foreign": "prs_bedrijf",
            "label": L("lcl_bes_Supplier")
        },
        "orderdate": {
            "dbs": "bes_bestelopdr_datum",
            "typ": "datetime",
            "label": L("lcl_bes_add_date"),
            "defaultvalue": new Date()
        },
        "deliveryaddress": {
            "dbs": "mld_adres_key_lev",
            "typ": "key",
            "foreign": "mld_v_afleveradres",
            "label": L("lcl_bes_adres_lev")
        },
        "invoiceaddress": {
            "dbs": "mld_adres_key_fac",
            "typ": "key",
            "foreign": "mld_v_factuuradres",
            "label": L("lcl_bes_adres_fac")
        },
        "deliverydate": {
            "dbs": "bes_bestelopdr_leverdatum",
            "typ": "datetime",
            "label": L("lcl_bes_deli_date")
        },
        "deliverycosts": {
            "dbs": "bes_bestelopdr_levkosten",
            "typ": "currency",
            "label": L("lcl_opdr_kosten")
        },
        "discount": {
            "dbs": "bes_bestelopdr_korting",
            "typ": "currency",
            "label": L("lcl_bes_discount")
        },
        "remark": {
            "dbs": "bes_bestelopdr_opmerking",
            "typ": "memo",
            "label": L("lcl_bes_remark")
        },
        "contract": {
            "dbs": "cnt_contract_key",
            "typ": "key",
            "foreign": "cnt_contract",
            "label": L("lcl_cnt_intern_nr")
        },
        "orderfor": {
            "dbs": "prs_perslid_key",
            "typ": "key",
            "foreign": "prs_perslid",
            "label": L("lcl_bes_order_for")
        },
        "deliveryremark": {
            "dbs": "bes_bestelopdr_delivery_opmerk",
            "typ": "memo",
            "label": L("lcl_bes_bestelling_lev_opm")
        },
        "flags": {
            "dbs": "bes_bestelopdr_flag",
            "typ": "number",
            "label": L("lcl_bestelopdr_flags")
        },
        "externnr": {
            "dbs": "bes_bestelopdr_externnr",
            "typ": "varchar",
            "label": L("extern_nr"),
            "readonly": !(user.has("WEB_FACTAB") || user.has("WEB_FACXNR"))
        },
        "externsyncdate": {
            "dbs": "bes_bestelopdr_externsyncdate",
            "typ": "datetime",
            "label": L("extern_syncdate"),
            "readonly": !(user.has("WEB_FACTAB") || user.has("WEB_FACXNR"))
        }
    };


    function _check_authorization(params, method)
    {
        switch (method)
        {
            case "GET": var this_bes = bes.func_enabled_bestelopdracht(params.filter.id);
                        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);
}
%>