<%@language = "javascript" %>
<% /*
    $Revision$
    $Id$

    File:           mld_opdr.asp

    Description:    fac_management aanroep van model_mld_opdr

    Context:

    Notes:
*/
    THIS_FILE = "appl/bgt/mld_opdr.asp";

%>
<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../api2/model_mld_opdr.inc" -->
<%
var parent = getQParam("parent", "");
var project_key = getQParamInt("budgetproject", -1);
var kostenrubriek_key = getQParamInt("budgetcostcategory", -1);
var kostensoortgrp_key = getQParamInt("costtypegroup", -1);
var kostensoort_key = getQParamInt("costtype", -1);
var opdr_key = getQParamInt("id", -1);
var this_model = new model_mld_opdr();

if (mode == "show")
{
    var autparams = user.checkAutorisation(this_model.autfunction);
    var canWrite = (autparams.PRSwritelevel < 9 && autparams.ALGwritelevel < 9)
    if (!canWrite)
    {
        delete this_model.REST_PUT;
    }
    this_model.fields.ordernr_sort.hidden_fld = false;
    this_model.fields.ordernr_sort.readonly = true;
}
if (mode == "edit")
{
%>
    <script>
        var cur_mode = (<%=opdr_key%> > 0 ? "order_edit" : "order_new");
    </script>
<%
}
if (mode == "list")
{
    this_model.fields.company.foreign = bgt_company_foreign(1);
}
if (mode == "search")
{
    // Onderstaand script is nodig om vanuit budgetbeheer naar het scherm Contracten te
    // gaan, waarbij de selectievelden ingevuld worden met de bekende waarden.
%>
    <script>
        if (<%=kostenrubriek_key%>  >= -1) var budgetcostcategory_key = <%=kostenrubriek_key%>;
        if (<%=kostensoortgrp_key%> >= -1) var costtypegroup_key = <%=kostensoortgrp_key%>;
        if (<%=kostensoort_key%>    >= -1) var costtype_key = <%=kostensoort_key%>;
    </script>
<%
}

var model_params = {
    "search": {
        "autosearch": ((parent == "search") ? true : false),
        "filters": [
            "budgetdiscipline",
            "budgetproject",
            "budgetcostcategory",
            "costtypegroup",
            "costtype",
            "reference",
            "company",
            "additional"
        ],
        "transit": [
            "budgetdiscipline",
            "budgetproject",
            "budgetcostcategory",
            "costtypegroup",
            "costtype",
            "company",
            "reference",
            "account",
            "startdate"
        ],
        "requires": {
            "js": ["../bgt/bgt_budget.js"]
        }
    },
    "list": {
        "columns": [
            "costtype",
            "company",
            "ordernr",
            "sequence",
            "description",
            "reference",
            "startdate",
            "estimate",
            "contracted",
            "invoiced",
            "tobeinvoiced",
            "additional",
            "budgetproject"
        ],
        "orderby": [
            "ordernr_sort",
            "sequence",
            "reference"
        ]
    },
/*
// TWYN#53173 Ook kunnen kopieren van een opdracht (nieuw opdrachtnummer genereren, en volgnr=0)
        "show": {
            "no_clone": true,
            "buttons": [
                {
                    "title": "Nieuwe opdracht", //L("lcl_opdr_new_opdr"),
                    "action": "scf_clone()",
                    "icon": "fa-clone"
                },
                {
                    "title": "Nieuwe subopdracht", //L("lcl_opdr_new_subopdr"),
                    "action": "scf_clone(2)", // Let op: de betekenis van hoofd- en subopdracht zijn nu omgedraaid!
                    "icon": "fa-copy"
                }
            ]
        },
*/
    "edit": {
        "requires": {
            "js": ["../bgt/mld_opdr.js"]
        }
    },
    "layout": {
        "miscellaneous": L("lcl_mld_miscellaneous_fields"),
        "block": [
            {
                "blockid": "scfLayout_L",
                "label": "",
                "ishtmlsafe": true,
                "hidden": false,
                "buttons": [],
                "fields": [
                    "budgetdiscipline",
                    "budgetproject",
                    "budgetcostcategory",
                    "costtypegroup",
                    "costtype",
                    "company",
                    "reference",
                    "ordernr",
                    "ordernr_sort",
                    "sequence",
                    "account"
                ]
            },
            {
                "blockid": "scfLayout_R",
                "label": "",
                "fields": [
                    "description",
                    "startdate",
                    "amount",
                    "vat",
                    "amountincl",
                    "invoiced",
                    "tobeinvoiced",
                    "status",
                    "additional",
                    "remark"
                ]
            },
            {
                "blockid": "mldHidden",
                "label": L("lcl_mld_hidden_fields"),
                "hidden": true,
                "fields": [
                    "startdate_range",
                    "estimate",
                    "contracted",
                    "owner",
                    "issueordertype",
                    "module",
                    "_is_clone",
                    "offer",
                    "issue",
                    "contract"
                ]
            }
        ]
    },
    "wrap": {
        "no_default_frames": true,
        "frames": [ { title: L("lcl_fin_invoices_frame"),
                      url: "./fin_factuur.asp?mode=list&opdrachtcommon={0}"
                    } ]
    }
}

if (parent == "search")
{   // Scherm wordt aangeroepen vanuit bgt_search_list.
    model_params.transit = {
        "budgetcostcategory": kostenrubriek_key,
        "costtypegroup": kostensoortgrp_key,
        "costtype": kostensoort_key
    }
}

scaffolding(this_model, model_params);
%><% ASPPAGE_END(); %>
