<% /*
    $Revision$
    $Id$

    File:           model_bes_srtdeel.inc

    Description:    model voor bes_srtdeel

    Context:

    Notes:
*/
%>
<!-- #include file="../FAC/fac.inc" -->
<!-- #include file="../BES/bes.inc" -->
<%
function model_bes_srtdeel(disc_key)
{
    var enddate = getQParamDate("_enddate", null);

    this.records_name = "commodities";
    this.record_name = "commodity";
    this.table = "bes_srtdeel";
    this.primary = "bes_srtdeel_key";
    this.autfunction = "WEB_BESMSU";
    this.record_title = L("lcl_bes_srtdeel");
    this.records_title = L("lcl_bes_srtdeel_list");
    this.soft_delete = "bes_srtdeel_verwijder";

    this.fields = {
        "id": {
            "dbs": "bes_srtdeel_key",
            "seq": "bes_s_bes_srtdeel_key",
            "typ": "key",
            "label": L("lcl_key"),
            "required": true
        },
        "articlegroup": {
            "dbs": "bes_srtgroep_key",
            "typ": "key",
            "foreign": {
                "tbl": "bes_srtgroep",
                "key": "bes_srtgroep_key",
                "desc": "bes_srtgroep_omschrijving",
                "where": "bes_srtgroep_verwijder IS NULL" + (disc_key > -1 ? " AND ins_discipline_key = " + disc_key : "")
            },
            "label": L("lcl_bes_srtgroep_oms"),
            "required": true
        },
        "name": {
            "dbs": "bes_srtdeel_omschrijving",
            "typ": "varchar",
            "label": L("lcl_bes_srtdeel_oms"),
            "required": true,
            "len": 100
        },
        "remark": {
            "dbs": "bes_srtdeel_opmerking",
            "typ": "memo",
            "label": L("lcl_bes_opmerking")
        },
        "created": {
            "dbs": "bes_srtdeel_aanmaak",
            "typ": "datetime",
            "label": L("lcl_bes_srtdeel_aanmaak"),
            "defaultvalue": new Date(),
            "readonly": true
        },
        "sequence": {
            "dbs": "bes_srtdeel_volgnr",
            "typ": "number",
            "label": L("lcl_bes_srtdeel_volgnr")
        },
        "vat": {
            "dbs": "bes_srtdeel_btw",
            "typ": "float",
            "label": L("lcl_btw_percentage"),
            "multiedit": true
        },
        "unit": {
            "dbs": "bes_srtdeel_eenheid",
            "typ": "varchar",
            "label": L("lcl_bes_unity"),
            "multiedit": true
        },
        "dimension": {
            "dbs": "bes_srtdeel_dimensie",
            "typ": "check",
            "label": L("lcl_bes_srtdeel_dimensie")
        },
        "preview": {
            "dbs": "bes_srtdeel_preview",
            "typ": "check0",
            "label": L("lcl_bes_preview"),
            "defaultvalue": 0
        },
        "commoditynumber": {
            "dbs": "bes_srtdeel_nr",
            "typ": "varchar",
            "label": L("lcl_bes_srtdeel_nr"),
            "required": true,
            "len": 32
        },
        "supplier": {
            "dbs": "prs_bedrijf_key",
            "typ": "key",
            "foreign": "PRS_BEDRIJF",
            "foreignfiltercode": "L",
            "label": L("lcl_bes_Supplier"),
            "multiedit": true,
            "showtransit": true
        },
        "expirationdate": {
            "dbs": "bes_srtdeel_vervaldatum",
            "typ": "date",
            "label": L("lcl_bes_vervaldatum"),
            "multiedit": true
        },
        "image": {
            "dbs": "bes_srtdeel_image",
            "typ": "file",
            "module": "BESPH",
            "label": L("lcl_bes_image")
        },
        "multiple": {
            "dbs": "bes_srtdeel_veelvoud",
            "typ": "float",
            "label": L("lcl_bes_veelvoud"),
            "multiedit": true
        },
        "minimumorder": {
            "dbs": "bes_srtdeel_minimum",
            "typ": "number",
            "label": L("lcl_bes_minimum"),
            "multiedit": true
        },
        "maximumorder": {
            "dbs": "bes_srtdeel_maximum",
            "typ": "number",
            "label": L("lcl_bes_maximum"),
            "multiedit": true
        },
        "pacelistgroup": {
            "dbs": "bes_staffeltabel_key",
            "typ": "key",
            "foreign": {
                "tbl": "bes_staffeltabel",
                "key": "bes_staffeltabel_key",
                "desc": "bes_staffeltabel_naam"
            },
            "label": L("lcl_bes_staffelgroep")
        },
        "personalised": {
            "dbs": "bes_srtdeel_prsflex",
            "typ": "check0",
            "label": L("lcl_bes_prsflex"),
            "defaultvalue": 0
        },
        "minimumstock": {
            "dbs": "bes_srtdeel_voorraadmin",
            "typ": "number",
            "label": L("lcl_bes_voorraadmin"),
            "multiedit": true
        },
        "maximumstock": {
            "dbs": "bes_srtdeel_voorraadmax",
            "typ": "number",
            "label": L("lcl_bes_voorraadmax"),
            "multiedit": true
        },
        "deviationpct": {
            "dbs": "bes_srtdeel_margepct",
            "typ": "number",
            "label": L("lcl_bes_srtdeel_margepct")
        },
        "editdays": {
            "dbs": "bes_srtdeel_wijzigdagen",
            "typ": "number",
            "label": L("lcl_bes_wijzigdagen")
        },
        "canceldays": {
            "dbs": "bes_srtdeel_annuleerdagen",
            "typ": "number",
            "label": L("lcl_bes_annuleerdagen")
        },
        "depositpct": {
            "dbs": "bes_srtdeel_depotverdeelpct",
            "typ": "number",
            "label": L("lcl_bes_depotverdeelpct")
        },
        "stockroomlocation": {
            "dbs": "bes_srtdeel_notitie",
            "typ": "varchar",
            "label": L("lcl_bes_notitie")
        },
        //  "dbs": "bes_srtdeel_details_loc", "typ": "memo"
        "maximumbestel": {
            "dbs": "bes_srtdeel_maxbestel",
            "typ": "check0",
            "label": L("lcl_bes_bestelmax"),
            "defaultvalue": 0,
            "multiedit": true
        },
        "stockfactor": {
            "dbs": "bes_srtdeel_voorraadfactor",
            "typ": "number",
            "label": L("lcl_bes_voorraadfactor"),
            "defaultvalue": 1,
            "required": true
        },
        "objecttype": {
            "dbs": "ins_srtdeel_key",
            "typ": "key",
            "foreign": "ins_srtdeel",
            "label": L("lcl_bes_link_obj_type"),
            "module": "INS",
            "binding": 24, // Afdeling 0x8=8 (BIND_AFDELI) + Persoon0x10=16 (BIND_PERSOO).
            "infoPointer": { Url: "appl/ins/ins_srtdeel.asp?srtdeel_key=" }
        },
        "actualprice": {
            "dbs": "actualprice",
            "sql": "(bes.getsrtdeelprijs(bes_srtdeel_key, "+(enddate ? enddate.beginToSQL() : "NULL")+"))",
            "iscurrency": true,
            "label": L("lcl_bes_price_per_unity")
        },
        "catalog": {
            "dbs": "ins_tab_discipline.ins_discipline_key",
            "typ": "key",
            "foreign": {
                "tbl": "bes_v_aanwezigdiscipline",
                "key": "ins_discipline_key",
                "desc": "(" + lcl.xsql("ins_discipline_omschrijving", "ins_discipline_key") + ")",
                "where": (disc_key > -1 ? "ins_discipline_key = " + disc_key : "")
            },
            "label": L("lcl_bes_discipline"),
            "showtransit": true,
            "readonly": true
        },
        "_enddate": {
            "dbs": "dual._enddate",
            "typ": "datetime",
            "label": L("lcl_bes_peildatum"),
            "filterdefault": ":D",
            "filter": "exact"
        }
    };


    var qparams = {
            "GET": {
                "tables": [
                    "bes_srtgroep",
                    "ins_tab_discipline"
                ],
                "wheres": [
                    "bes_srtgroep.ins_discipline_key = ins_tab_discipline.ins_discipline_key",
                    "bes_srtgroep.bes_srtgroep_key = bes_srtdeel.bes_srtgroep_key"
                ],
                "orderbys": [
                    "ins_discipline_omschrijving",
                    "bes_srtgroep_omschrijving",
                    "bes_srtdeel_volgnr",
                    "bes_srtdeel_nr"
                ]
            }
        };

    if (enddate)
    {
        qparams.GET.wheres.push(" (bes_srtdeel_vervaldatum IS NULL OR "
                              + "  bes_srtdeel_vervaldatum >= " + enddate.beginToSQL() + ")"
                                )
    }

    this.REST_GET    = generic_REST_GET(this, qparams);
    this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this, {});
}
%>
