<% /*
    $Revision$
    $Id$

    File:           model_fac_importapp.inc

    Description:    Bewerken van import definities
                    (echt importeren van data gebeurt scheduled of eventueel
                     interactief via APPL\IMP\imp_search.asp)

    Context:

    Notes:
*/
%>
<%

function model_fac_import_app()
{
    this.records_name = "importfunctions";
    this.record_name = "importfunction";
    this.table = "fac_import_app";
    this.primary = "fac_import_app_key";
    this.autfunction = "WEB_FACTAB"; // FACTAB omdat er (gevoelige) padnamen in staan
    this.record_title = L("fac_import_app");
    this.records_title = L("fac_import_app_m");

    var obj_info = function (type, obj)
        {
            var namesql = "COALESCE(fac_import_app_prefix, 'FAC') || {0} || UPPER(fac_import_app_code)".format(safe.quoted_sql(obj));
            var sql = "{0} || ' ' || {1}".format(safe.quoted_sql(type), namesql)
                    + " || ' (' || COALESCE((SELECT 'Created: ' || TO_CHAR(CREATED, 'YYYY-MM-DD HH24:MI') || ', Updated: ' || TO_CHAR(LAST_DDL_TIME, 'YYYY-MM-DD HH24:MI')"
                    + "                        FROM USER_OBJECTS"
                    + "                       WHERE OBJECT_NAME = {0} AND OBJECT_TYPE = {1}), '***Not found, import will not work!***') || ')'".format(namesql, safe.quoted_sql(type));
            return sql;
        }

    this.fields = {
        "id": {
            "dbs": "fac_import_app_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "fac_s_fac_import_app_key"
        },
        "name": {
            "dbs": "fac_import_app_oms",
            "label": L("fac_import_app_oms"),
            "typ": "varchar",
            "hidden_fld": true,
            "defaultvalue": "Catalogus",
            "translate": true
        },
        "xsl": {
            "dbs": "fac_import_app_xsl",
            "label": L("fac_import_app_xsl"),
            "typ": "varchar"
        },
        "authorization": {
            "dbs": "fac_functie_key",
            "label": L("fac_functie_key"),
            "typ": "key",
            "foreign": "fac_functie",
            "required": true,
            "showtransit": true
        },
        "authorizationbrowse": {
            "dbs": "fac_import_app_browse_f_key",
            "label": L("fac_import_app_browse_f_key"),
            "typ": "key",
            "foreign": "fac_functie"
        },
        "orderdiscipline": {
            "dbs": "ins_discipline_key",
            "label": L("fac_ins_discipline_key"),
            "typ": "key",
            "foreign": {
                "tbl": "(SELECT ins_discipline_key"
                     + "      , ins_discipline_omschrijving"
                     + "   FROM bes_v_aanwezigdiscipline)",
                "key": "ins_discipline_key",
                "desc": "ins_discipline_omschrijving"
            },
            "showtransit": true
        },
        "code": {
            "dbs": "fac_import_app_code",
            "label": L("fac_import_app_code"),
            "typ": "varchar",
            "hidden_fld": true,
            "defaultvalue": "CATALOGUS"
        },
        "updproc": {
            "dbs": "proc",
            "label": "",
            "sql": obj_info("PROCEDURE", "_UPDATE_"),
            "typ": "varchar"
        },
        "company": {
            "dbs": "prs_bedrijf_key",
            "label": L("prs_bedrijf_key"),
            "typ": "key",
            "foreign": {
                "tbl": "(SELECT prs_bedrijf_key"
                     + "      , prs_bedrijf_naam"
                     + "   FROM prs_bedrijf"
                     + "  WHERE prs_bedrijf_leverancier = 1"
                     + "    AND prs_bedrijf_verwijder IS NULL"
                     + "  ORDER BY prs_bedrijf_naam)",
                "key": "prs_bedrijf_key",
                "desc": "prs_bedrijf_naam"
            },
            "showtransit": true
        },
        "charset": {
            "dbs": "fac_import_app_charset",
            "label": L("fac_import_app_charset"),
            "typ": "varchar"
        },
        "folder": {
            "dbs": "fac_import_app_folder",
            "label": L("fac_import_app_folder"),
            "typ": "varchar"
        },
        "files": {
            "dbs": "fac_import_app_files",
            "label": L("fac_import_app_files"),
            "typ": "varchar"
        },
        "prefix": {
            "dbs": "fac_import_app_prefix",
            "label": L("fac_import_app_prefix"),
            "typ": "varchar"
        },
        "delimiter": {
            "dbs": "fac_import_app_delimiter",
            "label": L("fac_import_app_delimiter"),
            "typ": "varchar"
        },
        "csv": {
            "dbs": "fac_import_app_csv",
            "label": L("fac_import_app_csv"),
            "typ": "check0"
        }
    };


    this.REST_GET    = generic_REST_GET(this,
                                           { "GET": {
                                               wheres: [ "fac_import_app_code='CATALOGUS'",
                                                         "NOT (ins_discipline_key IS NULL AND prs_bedrijf_key IS NULL)"
                                                       ]
                                               }
                                           }
                                       );
    this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this, {});
}
%>