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

    File:               get_bes_info_ajax.asp
    Description:        Ophalen van allerlei info om client-side data te hebben
    Parameters:         req_info:   "bes_bestelling"    --> requires "bes_bestelling_key"

    Context:
    Note:
    Sample:             appl/bes/get_bes_info_ajax.asp?req_info=bes_bestelling&bes_key=1

*/ %>

<%
var JSON_Result = true;
%>

<!-- #include file="../Shared/common.inc"-->
<!-- #include file="./bes.inc" -->

<%
var req_info = getQParam("req_info");
var result = {};
switch (req_info)
{
    case "func_enabled_bestelling":
    {
        var bes_key = getQParamInt("bes_key");
        var bes_bestelling = bes.bestelling_info(bes_key); // Globale variabele met alle bes_bestelling informatie
        //var bes_disc_info = bes.disc_info(bes_bestelling.dis_key); // alle discipline informatie
        var result = bes.func_enabled_bestelling(bes_bestelling);
        result.bes_key = bes_key;
        break;
    }
    case "voorraad_artikel":
    { // check whether stock control is enabled
        var sql = "SELECT bes_ins_discipline_key_inkoop"
                + "  FROM bes_srtgroep bsg,"
                + "       bes_srtdeel bsd,"
                + "       bes_disc_params dp"
                + " WHERE bsg.bes_srtgroep_key = bsd.bes_srtgroep_key"
                + "   AND bsd.bes_srtdeel_key = " + getQParamInt("srtdeel_key")
                + "   AND bsg.ins_discipline_key = dp.bes_ins_discipline_key";
        var oRs = Oracle.Execute(sql);
        var bes_disc_key = (oRs.eof ? oRs("bes_ins_discipline_key_inkoop").Value : null);
        oRs.Close();
        if (bes_disc_key)
        {
            var urole = getQParam("urole");
            switch(urole)
            {
                case "fe": autfunction = "WEB_BESUSE"; break;
                case "fo": autfunction = "WEB_BESFOF"; break;
                case "bo": autfunction = "WEB_BESBOF"; break;
                case "mi": autfunction = "WEB_BESBAC"; break;
            }
            params = { catalogus_key: null
                    , besgroep_key: null
                    , item_key: getQParamInt("srtdeel_key")
                    , searchtekst: null
                    , tebestellen: null
                    };
            var sql = bes.voorraad_srtdeel(autfunction, params);
            var oRs = Oracle.Execute(sql);
            if (!oRs.eof)
            {
                result = { srtdeel_key: oRs("bes_srtdeel_key").Value
                        , voorraadmin: oRs("voorraadmin").Value
                        , voorraadmax: oRs("voorraadmax").Value
                        , maxbestel: oRs("maxbestel").Value
                        , bestelmin: oRs("bestelmin").Value
                        , bestelmax: oRs("bestelmax").Value
                        , bestelveelvoud: oRs("bestelveelvoud").Value
                        , voorraad: oRs("voorraad").Value
                        , voorraad_intern: oRs("voorraad_intern").Value
                        };
            }
            oRs.Close();
        }
        break;
    }
}

Response.Write(JSON.stringify(result));
%>
<% ASPPAGE_END(); %>
