<%@ LANGUAGE="JavaScript" %>
<% /*
     $Revision$
     $Id$

    File:               sup_detail.asp
    Description:        Muteerscherm voor supervisor

    Parameters:         mld_opdr_key: key van de opdracht

    Context:            Vanuit de klantspecifieke rapportage asle_v_work_list_supervisor

    Note:               Terminologie:

*/ %>


<!-- #include file='../../../appl/scf/scaffolding_m.inc' -->
<!-- #include file='../../../appl/api2/model_orders.inc' -->
<!-- #include file='../../../appl/api2/model_issues.inc' -->
<!-- #include file="../../../appl/mld/mld.inc" -->
<!-- #include file="../../../appl/mld/mld_flexkenmerk.inc" -->

<%
    var id = getQParamInt("id");
    var cparams = { filter: { scope: "bo" }};
    var orders = new model_orders(id,  cparams);

    switch (mode)
    {
        case "edit":
            function fnFlexClean() // Found Clean
            {
              generateFlexKenmerkBlock ({ fnpre: function () {},
                                          fnpost: function () {},
                                          opdr_key: orders.data.id,
                                          opdr_type: orders.data.ordertype.id,
                                          opdr_type_org: orders.data.ordertype.id,
                                          opdr_status: orders.data.ordertype.id,
                                          mld_key: orders.data.issue.id,
                                          kenmerk_keys: [21], // Alleen 'Found Clean'
                                          showClose: false,
                                          mobile: true,
                                          reado: false
                                        });
            }
            function fnFlexReClean() // Herschoonmaak opmerking
            {
              generateFlexKenmerkBlock ({ fnpre: function () {},
                                          fnpost: function () {},
                                          opdr_key: orders.data.id,
                                          opdr_type: orders.data.ordertype.id,
                                          opdr_type_org: orders.data.ordertype.id,
                                          opdr_status: orders.data.ordertype.id,
                                          mld_key: orders.data.issue.id,
                                          kenmerk_keys: [101], // Opmerking over herschoonmaak
                                          showClose: false,
                                          mobile: true,
                                          reado: true
                                        });
            }
            function fnFlexNewCleaner() // Herschoonmaak opmerking
            {
              generateFlexKenmerkBlock ({ fnpre: function () {},
                                          fnpost: function () {},
                                          opdr_key: orders.data.id,
                                          opdr_type: orders.data.ordertype.id,
                                          opdr_type_org: orders.data.ordertype.id,
                                          opdr_status: orders.data.ordertype.id,
                                          mld_key: orders.data.issue.id,
                                          kenmerk_keys: [121], // Nieuwe schoonmaker
                                          showClose: false,
                                          mobile: true,
                                          reado: false
                                        });
            }
            function fnFlexNoService() // NoService in geval van StayOver
            {
              generateFlexKenmerkBlock ({ fnpre: function () {},
                                          fnpost: function () {},
                                          opdr_key: orders.data.id,
                                          opdr_type: orders.data.ordertype.id,
                                          opdr_type_org: orders.data.ordertype.id,
                                          opdr_status: orders.data.ordertype.id,
                                          mld_key: orders.data.issue.id,
                                          kenmerk_keys: [141], // NoService
                                          showClose: false,
                                          mobile: true,
                                          reado: false
                                        });
            }
            orders.fields["description"].readonly = true; // TODO: Moet eigenlijk vanzelf via rechten?
            orders.fields["plandate"].readonly = true;
            orders.fields["plandate"].label = 'Beschikbaar';
            orders.fields["enddate"].readonly = true;

            var melding_key = orders.data.issue.id;

            var calls = new model_issues(melding_key, { filter: { scope: "bo"}});

            var cleaning_type = calls.data.issuetype.id;

            var ostat = orders.data.status.id;
            var loc = orders.data.location.id;
            var bld = orders.data.building.id;
            var flr = orders.data.floor.id;
            var room = orders.data.room.id;
            var uitv_key = orders.data.supplier.id;
            var mld_key = orders.data.issue.id;
            var ordertype_key = orders.data.ordertype.id;
            if (ordertype_key == 101)
            {
                orders.data.description = 'Herschoonmaak';
            }

            orders.edit = { fields: [ "plandate", "description"],
                            buttons: []
                                };

            if (ostat == 6) // afgemeld
            {
                orders.edit.buttons.push({ label: "OK", params: {click: "asle_sOK()", dataicon: "check"}});
                orders.edit.buttons.push({ label: "NOK", params: {click: "asle_sNOK("+mld_key+","+uitv_key+")", dataicon: "delete"}});
                orders.edit.buttons.push({ label: "Call", params: {click: "asle_sCall("+loc+","+bld+","+flr+","+room+")", dataicon: "edit"}});
                if (cleaning_type == 2 || cleaning_type == 3) // (cleaning_type == 'Stay LC' || cleaning_type == 'Stay NLC')
                {
                    orders.edit.fields.push(fnFlexNoService);
                }
                else
                {
                    orders.edit.fields.push(fnFlexClean);
                }
                orders.edit.fields.push(fnFlexReClean);
            }
            else if (ostat == 5) // uitgegeven
            {
                orders.edit.buttons.push({ label: "Re-Plan", params: {click: "asle_sPlan()", dataicon: "check"}});
                orders.edit.fields.push(fnFlexNewCleaner);
            }
            else if (ostat == 8) // geaccepteerd
            {
                orders.edit.buttons.push({ label: "Klaar", params: {click: "asle_sReady()", dataicon: "check"}});
                orders.edit.fields.push(fnFlexClean);
                orders.edit.fields.push(fnFlexReClean);
            }
            orders.edit.fields.push("remark");
            orders.edit.buttons.push({ label: "Lijst", params: {click: "asle_sBack()", dataicon: "home"}});
            orders.hook_pre_edit = function (obj)
            {
                orders.record_title = L("lcl_room") + ": " + obj.room.name;
            }

            var scf_params = { "edit": { requires: { js: ["./asle.js"] }}};

            break;
        case "save":
            if (getQParamInt("NOK", 0) == 1 || getQParamInt("OK", 0) == 1)
            {
                orders.hook_pre_put = function (params, orderdata, key)
                {
                    var opdracht_data = orders.REST_GET({ filter: { "id": key, scope: "bo" }})[0];
                    // Afronden
                    orderdata.status = 9;
                    //__DoLog(orderdata);
                }
            }
            if (getQParamInt("Ready", 0) == 1)
            {
                orders.hook_pre_put = function (params, orderdata, key)
                {
                     //var opdracht_data = orders.REST_GET({ filter: { "id": key, scope: "bo" }})[0];
                    // Afmelden
                    orderdata.status = 6;
                }
            }
            if (getQParamInt("plan", 0) == 1)
            {
                if (getFParamInt("k1key", 1) == 121 )   // nieuwe schoonmaker veld gevuld
                {
                    var new_cleaner_key = getFParamInt("k1val");
                    orders.hook_pre_put = function (params, orderdata, key)
                    {
                        orderdata.supplier = new_cleaner_key;
 //                       __DoLog(jsondata);
                    }
                }
            }
            break;

    }
    scaffolding(orders, scf_params);

%>
