<% /*
    $Revision$
    $Id$

    File:           model_issuetypes.inc

    Description:    Model voor mld_stdmelding

    Context:

    Notes:          Normaal gesproken krijg je bij een foreign alleen de id en de de name
                    Voor discipline maken we hier echter een uitzondering: in de praktijk
                    heb je de info daarvan er eigenlijk altijd ook wel bij nodig
*/
%>
<!-- #include file="./model_mld_discipline.inc" -->
<%
function model_issuetypes(stdm_key, params)
{
    params = params || {};
    this.table = "mld_stdmelding";
    this.primary = "mld_stdmelding_key";
    this.records_name = "issuetypes";
    this.record_name = "issuetype";
    this.fields = {
      "id": {
        "dbs": "mld_stdmelding_key",
        "label": "Key",
        "typ": "key",
        "filter": "exact",
        "seq": "mld_s_mld_stdmelding_key"
      },
      // Ik kan geen logisch "name" veld bedenken
      discipline:     { dbs: "mld_ins_discipline_key",                     typ: "key",     "foreign": "MLD_DISCIPLINE", label: L("lcl_mld_vakgroep") },
      description:    { dbs: "mld_stdmelding_omschrijving",                typ: "varchar", label: L("lcl_mld_inf_Omschrijving") },
      //                { dbs: "mld_stdmelding_notfrontend",                 typ: "check0",  frm: "notfrontend" },
      costtype:       { dbs: "prs_kostensoort_key",                        typ: "key",     foreign: "prs_kostensoort",   label: L("lcl_shared_charge_type"), filter: "exact" },
      //              { dbs: "alg_onrgoed_niveau",                         typ: "varchar", frm: "onrgoed_niveau" },
      //              { dbs: "mld_stdmelding_notify",                      typ: "check0",  frm: "notify" },
      //              { dbs: "mld_stdmelding_planbaar",                    typ: "check0",  frm: "planbaar" },
      //              { dbs: "mld_stdmelding_freetext",                    typ: "key",     frm: "freetext" },
      //              { dbs: "ins_srtinst_verplicht",                      typ: "check0",  frm: "obj_verplicht" },
      "hint":         { dbs: "mld_stdmelding_hint",                        typ: "varchar", label: L("lcl_mld_hint") },
      "autoorder":    { dbs: "mld_stdmelding_autoorder",                   typ: "check0",  label: L("lcl_mld_autoorder") },
      requireservice: { dbs: "mld_stdmelding_vereisdienst",                typ: "check0",  label: L("lcl_mld_vereisdienst") },
      issuegroup:     { dbs: "mld_stdmeldinggroep_key",                    typ: "key",     label: L("lcl_mld_meldinggroep") },
      service:        { dbs: "prs_dienst_key",                             typ: "key",     label: L("lcl_mld_behandel_dienst"), foreign: "prs_dienst" },
      ordertype:      { dbs: "mld_typeopdr_key",                           typ: "key",     label: L("lcl_mld_typeopdr") },
      //              { dbs: "mld_stdmelding_regime",                      typ: "key",     frm: "regime" },
      //              { dbs: "mld_stdmelding_malus",                       typ: "float",   frm: "malus" },
      //              { dbs: "mld_stdmelding_afhankelijk",                 typ: "check0",  frm: "afhankelijk" },
      //              { dbs: "mld_stdmelding_image",                       typ: "varchar", frm: "image" },
      //              { dbs: "mld_stdmelding_afmeldtext",                  typ: "key",     frm: "afmeldtext" },
      //              { dbs: "mld_stdmelding_volgnr",                      typ: "number",  frm: "volgnummer" },
      //              { dbs: "mld_stdmelding_prseigen",                    typ: "check0",  frm: "prseigen" },
      //              { dbs: "mld_stdmelding_doublecheck",                 typ: "key",     frm: "doublecheck" },
      //              { dbs: "mld_stdmelding_kopieerbaar",                 typ: "check0",  frm: "kopieerbaar" },
      //              { dbs: "mld_stdmelding_kto",                         typ: "key",     frm: "kto" },
      //              { dbs: "bes_ins_discipline_key",                     typ: "key",     frm: "bes_disc_key" },
      //              { dbs: "mld_stdmelding_vervaldatum",                 typ: "date",    frm: "vervaldatum" },
      //              { dbs: "mld_stdmelding_opdrtypevast",                typ: "check0",  frm: "opdrtypevast" },
      immediateready:  { dbs: "mld_stdmelding_directklaar",                typ: "key",     label: L("lcl_mld_directklaar"), LOV: api2.makeLOV([L("lcl_No"), L("lcl_Yes"), L("lcl_mld_initieel_fo")]) },
      ximmediateready: { dbs: "xmld_stdmelding_directklaar",              typ: "key",     sql: "COALESCE(mld_stdmelding_directklaar, mld_disc_params_directklaar, 0)" }
      //              { dbs: "mld_stdmelding_slabewaken",                  typ: "check0",  frm: "slabewaken" },
      //              { dbs: "alg_onrgoed_obj_niveau",                     typ: "varchar", frm: "obj_show_niveau" },
      //              { dbs: "alg_org_obj_niveau",                         typ: "number",  frm: "org_obj_niveau" },
      //              { dbs: "mld_stdmelding_t_uitvoertijd.tijdsduur",
      //                obj: "MLD_T_UITVOERTIJD",                          typ: "float",  frm: "uitvoertijd3" },
      //              { dbs: "mld_stdmelding_t_uitvoertijd.eenheid",
      //                obj: "MLD_T_UITVOERTIJD",                          typ: "varchar", frm: "dayshours3" }
      }
    this.list = {
      "columns": [
        "id",
        "discipline",
        "description",
        "issuegroup",
        "service"
      ]
    };
    this.search = {
      "autosearch": true,
      "filters": ["discipline"]
    };
    this.soft_delete = "mld_stdmelding_verwijder";
    this.autfunction = "WEB_MLDMGT";
    this.record_title = L("lcl_mld_standaardmelding");
    this.records_title = L("lcl_mld_stdmeldingen");

    api2.generic_REST(this, { GET: { tables: [ "ins_tab_discipline, mld_disc_params, ins_srtdiscipline" ],
                                     wheres: [ "ins_tab_discipline.ins_discipline_key = mld_stdmelding.mld_ins_discipline_key",
                                               "mld_disc_params.mld_ins_discipline_key = mld_stdmelding.mld_ins_discipline_key",
                                               "ins_tab_discipline.ins_srtdiscipline_key = ins_srtdiscipline.ins_srtdiscipline_key"
                                             ]
                                   }
                            });

    if (stdm_key > 0)
    {
        params.filter = params.filter || {};
        params.filter.id = stdm_key;

        var xxx_array = this.REST_GET(params);
        if (!xxx_array.length)
            shared.record_not_found();
        this.data = xxx_array[0];
        this.data.discipline = new model_discipline("MLD", this.data.discipline.id);
    }
}


%>