<% /*
    $Revision$
    $Id$

    File:           model_bgt_kostenrubriek.inc

    Description:    Model voor bgt_kostenrubriek

    Context:

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

function model_bgt_kostenrubriek()
{
    this.records_name = "budgetcostcategories";
    this.record_name = "budgetcostcategory";
    this.table = "bgt_kostenrubriek";
    this.primary = "bgt_kostenrubriek_key";
    this.autfunction = "WEB_BGTMAN";
    this.record_title = L("bgt_kostenrubriek");
    this.records_title = L("bgt_kostenrubriek_m");

    this.fields = {
        "id": {
            "dbs": "bgt_kostenrubriek_key",
            "label": L("lcl_key"),
            "typ": "key",
            "hidden_fld": true,
            "required": true,
            "seq": "bgt_s_bgt_kostenrubriek_key"
        },
        "budgetproject": {
            "dbs" : "bgt_project_key",
            "label": L("bgt_project_omschrijving"),
            "typ": "key",
            "required": true,
            "insertonly": true,
            "foreign": {
                "tbl": "bgt_project",
                "key": "bgt_project_key",
                "desc": "bgt_project_omschrijving",
                "where": "bgt_project_verwijder IS NULL"
            },
            "showtransit": true
        },
        "name": {
            "dbs": "bgt_kostenrubriek_oms",
            "label": L("bgt_kostenrubriek_oms"),
            "typ": "varchar",
            "required": true,
            "translate": true
        },
        "code": {  /* vermoeden: gaat nog volgnr worden en/of kan vervallen */
            "dbs": "bgt_kostenrubriek_code",
            "label": L("bgt_kostenrubriek_code"),
            "typ": "varchar"
        },
        "vat": {
            "dbs": "fin_btwtabelwaarde_key",
            "label": L("lcl_btw_percentage"),
            "typ": "key",
            "foreign": {
                "tbl": "fin_btwtabelwaarde",
                "key": "fin_btwtabelwaarde_key",
                "desc": "fin_btwtabelwaarde_oms"
            }
        }
    };

    this.print = { xmlnode: "budget", where: "kostenrubriek"};

    this.hook_pre_post = function(params, obj)
    {
        var sql = "SELECT 1"
                + "  FROM bgt_kostenrubriek"
                + " WHERE bgt_project_key = " + obj.budgetproject
                + "   AND bgt_kostenrubriek_code = " + safe.quoted_sql_upper(obj.code);
        var oRs = Oracle.Execute(sql);
        if (!oRs.eof)
            abort_with_warning(L("bgt_kostenrubriek_err2"));
        oRs.Close();

        if (obj.code != "R" && obj.vat != -1)
            abort_with_warning(L("bgt_kostenrubriek_err1"));
    }

    this.hook_pre_put = function(params, obj, key)
    {
        var sql = "SELECT 1"
                + "  FROM bgt_kostenrubriek"
                + " WHERE bgt_project_key = "
                            + "(SELECT bgt_project_key"
                            + "   FROM bgt_kostenrubriek"
                            + "  WHERE bgt_kostenrubriek_key = " + key
                            + ")"
                + "   AND bgt_kostenrubriek_code = " + safe.quoted_sql_upper(obj.code)
                + "   AND bgt_kostenrubriek_key <> " + key;
        var oRs = Oracle.Execute(sql);
        if (!oRs.eof)
            abort_with_warning(L("bgt_kostenrubriek_err2"));
        oRs.Close();

        if (obj.code != "R" && obj.vat != -1)
            abort_with_warning(L("bgt_kostenrubriek_err1"));
    }

    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);
}
%>