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

    File:           fin_factuur.asp

    Description:    aanroep van model_fin_factuur

    Context:

    Notes:
*/
%>
<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../api2/model_fin_factuur.inc" -->
<%
var parent  = getQParam("parent", "");
var isClone = getQParamInt("scf_clone",0) == 1;
var fac_key = getQParamInt("id", -1);
var discipline_key  = getQParamInt("budgetdiscipline", -1);
var project_key     = getQParamInt("budgetproject", -1);
var kostensoort_key = getQParamInt("costtype", -1);
var p_mld_opdr_key  = getQParamInt("opdrachtcommon", -1);
p_mld_opdr_key = (p_mld_opdr_key == -1 ? getQParamInt("order", -1) : p_mld_opdr_key);

var sql = "SELECT p.ins_discipline_key"
        + "     , p.bgt_project_key"
        + "  FROM bgt_v_project_full p"
        + "     , mld_opdr o"
        + "     , fin_factuur f"
        + " WHERE p.prs_kostensoort_key = o.prs_kostensoort_key"
        + "   AND f.mld_opdr_key = o.mld_opdr_key"
        + "   AND f.fin_factuur_key = " + fac_key;
var oRs = Oracle.Execute(sql);
var p_discipline_key = (!oRs.eof ? oRs("ins_discipline_key").Value : -1);
var p_project_key    = (!oRs.eof ? oRs("bgt_project_key").Value    : -1)
oRs.Close();


var this_model = new model_fin_factuur();

if (mode == "list")
{
    this_model.fields.company.foreign = bgt_company_foreign(1);
}
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;
    }
}



var model_params = {
    "search": {
        "autosearch": ((parent == "search") ? true : false),
        "filters": [
            "budgetdiscipline",
            "budgetproject",
            "costtype",
            "company",
            "order",
            "additional",
            "isprinted",
            "date",
            "invoice",
            "status"
        ],
        "transit": [  // budgetdiscipline en budgetproject worden later conditioneel toegevoegd
            "costtype",
            "company",
            "order"
        ],
        "requires": {
            "js": ["../bgt/fin_factuur.js"]
        }
    },
    "list": {
        "columns": [
            "costtype",
            "company",
            "ordernr",
            "orderseq",
            "date",
            "invoice",
            "remark",
            "total",
            "totalvat",
            "totalincl",
            "advice",
            "additional",
            "budgetproject"
        ],
        "orderby": [
            "invoice",
            "date"
        ]
    },
    "edit": {
        "requires": {
            "js": ["../bgt/fin_factuur.js"]
        }
    },
    "transit": {
        "opdrachtcommon": p_mld_opdr_key
    },
    "layout": {
        "search_block": [
            {   "filters": [
                    "budgetdiscipline",
                    "budgetproject",
                    "costtype",
                    "company",
                    "order"
                ]
            },
            {   "filters": [
                    "additional",
                    "isprinted",
                    "date",
                    "invoice",
                    "status"
                ]
            }
        ],
        "miscellaneous": L("lcl_mld_overig"),
        "block": [
            {   "blockid": "bgtalg",
                "label": L("bgt_ksgbudget"),
                //"icon": "fa-user",
                "ishtmlsafe": true,
                "hidden": false,
                "buttons": [],
                "fields": [
                    "budgetdiscipline",
                    "budgetproject",
                    "costtype",
                    "company",
                    "order",
                    "account"
                ]
            },
            {   "blockid": "bgtfact",
                "label": L("bgt_factuur_gegevens"),
                //"icon": "fa-map-marker",
                "ishtmlsafe": true,
                "hidden": false,
                "buttons": [],
                "fields": [
                    "_staticinvoice",
                    "invoice",
                    "remark",
                    "date",
                    "advice",
                    "month",
                    "total",
                    "totalvat",
                    "totalincl"
                ]
            },
            {   "blockid": "bgtstat",
                "label": L("bgt_status"),
                //"icon": "fa-tag",
                "ishtmlsafe": true,
                "hidden": false,
                "buttons": [],
                "fields": [
                    "additional",
                    "status",
                    "isprinted"
                ]
            },
            {   "blockid": "bgthidden",
                "label": L("lcl_mld_hidden_fields"),
                "hidden": true,
                "fields": [
                    "budgetcostcategory"
                ]
            }
        ]
    }
}

if (parent == "search")
{   // Scherm wordt aangeroepen vanuit bgt_search_list.
    // NB: Dit is een andere conditie dan mode=search!
    model_params.transit = {
        costtype: kostensoort_key,
        opdrachtcommon: p_mld_opdr_key
    }
}

if (mode == "search")
{
    // Onderstaand script is nodig om vanuit budgetbeheer naar het scherm Facturen te
    // gaan, waarbij de selectievelden ingevuld worden met de bekende waarden.
%>
    <script>
        if (<%=p_mld_opdr_key%>  >= -1) var order_key = <%=p_mld_opdr_key%>;
        if (<%=kostensoort_key%> >= -1) var costtype_key = <%=kostensoort_key%>;
    </script>
<%
}

if (mode == "list")
{
    model_params.transit.budgetdiscipline = discipline_key;
}

if (mode == "wrap")
{
    if (isClone && fac_key > -1)
    {   // Bij het maken van een kopie van de factuur moet ongeacht de filterparameters
        // wel de keys van project en deelproject doorgegeven worden.
        model_params.transit.budgetdiscipline = p_discipline_key;
        model_params.transit.initproject = p_project_key;
    }
    else if (discipline_key > -1)
    {
        model_params.transit.budgetdiscipline = discipline_key;
    }
}

if (mode == "show")
{
    model_params.transit.budgetdiscipline = p_discipline_key;
}

if (mode == "edit")
{
    model_params.search.transit.push("budgetdiscipline");
    model_params.search.transit.push("budgetproject");
%>
    <script>
        if (<%=discipline_key%>  >= -1) var budgetdiscipline_key = <%=discipline_key%>;
        if (<%=project_key%>  >= -1)    var budgetproject_key = <%=project_key%>;
        if ("<%=isClone%>"=="True")     var initproject_key = <%=p_project_key%>;
    </script>
<%
}


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