<?xml version="1.0" encoding="windows-1252"?>
<![CDATA[
/*
    $Id$

    File:       puo_putorders.WSC
    Context:    Vanuit de ASP code (Immediate)
    Note:       (de file puo_putorders.wsf is degene die vanuit
                 de scheduled task aangeroepen wordt)

*/
]]>
<component>
<?component error="true" debug="true"?>
<registration
	description="puo_putorders"
	progid="puo_putorders.WSC"
	version="1.00"
	classid="{6D817B6F-9D08-4636-AAD9-8BD7C5EFF56A}"
>
</registration>

<public>

<!-- properties -->

<!-- methods -->
	<method name="initialize">
		<PARAMETER name="params"/>
	</method>
	<method name="sendMLDorders">
		<PARAMETER name="opdr_key"/>
		<PARAMETER name="params"/>
	</method>
	<method name="puo_send_planrequest">
		<PARAMETER name="prs_bedrijf_key"/>
		<PARAMETER name="request_xml"/>
	</method>
	<method name="puo_sendMail">
		<PARAMETER name="adrTo"/>
		<PARAMETER name="strSubj"/>
        <PARAMETER name="strBody"/>
        <PARAMETER name="params"/>
	</method>
	<method name="puo_sendSMS">
		<PARAMETER name="telnr"/>
		<PARAMETER name="msg"/>
	</method>
	<method name="puo_sendAPP">
		<PARAMETER name="prs_key"/>
		<PARAMETER name="msg"/>
		<PARAMETER name="url"/>
	</method>
</public>

<script language="javascript" src="../wsf_shared.js"></script>
<script language="javascript" src="puo_shared.js"></script>
<script language="javascript" src="puo_crackURL.js"></script>
<script language="javascript" src="puo_xmltools.js"></script>
<script language="javascript" src="puo_base64.js"></script>
<script language="javascript" src="puo_connector.js"></script>
<script language="javascript" src="puo_sendfile.js"></script>
<script language="javascript" src="puo_sendmail.js"></script>
<script language="javascript" src="puo_sendhttp.js"></script>
<script language="javascript" src="puo_sendsoap.js"></script>
<script language="javascript" src="puo_sendftp.js"></script>
<script language="javascript" src="puo_sendsftp.js"></script>
<script language="javascript" src="puo_sendsms.js"></script>
<script language="javascript" src="puo_sendapp.js"></script>
<script language="javascript" src="json2.js"></script>
<script language="javascript" src="puo_md5.js"></script>
<script language="javascript" src="puo_send2address.js"></script>
<script language="javascript" src="puo_hook.js"></script>
<script language="javascript" src="puo_notifications.js"></script>

<script language="javascript">
<![CDATA[

/*	properties	*/


/*	methods	*/
/*
/*
    $Revision$
    $Id$

    File:   puo_putorders.wsc
*/
/* Globals */
var S;
var settings;
var Oracle;
var customerId;
var PUO_LOGPATH;
var custabspath;
var userident;
var forceOrders = 0; // Niet ondersteund in immediate mode, het zal toch bijna altijd de eerste keer falen zijn
var clearNotifications = 1; // Altijd in immediate mode

function initialize(params)
{
    S = params.S;
    settings = params.settings; // voor overrule
    Oracle = params.Oracle;
    customerId = params.customerId;
    custabspath = params.custabspath;
    PUO_LOGPATH = params.PUO_LOGPATH;
    userident = params.userident;
}

// Forceer verzenden van één melding opdracht (vanuit ASP code)
// return false bij errors
function sendMLDorders(opdr_key, params)
{
    return { message: "Immediate is deprecated" }; // gewoon door de scheduled
}

function puo_send_planrequest(prs_bedrijf_key, request_xml)
{
    var XMLnode = 'planrequest';

    Log2File(1, "\n====== " + XMLnode + " start (" + toDateTimeString(new Date()) + ")");

    // eerst bedrijfadres_key bepalen
    var sqlB = "SELECT prs_bedrijfadres_key "
             + "  FROM prs_bedrijfadres ba "
             + " WHERE ba.prs_bedrijf_key = " + prs_bedrijf_key
             + "   AND prs_bedrijfadres_startdatum <= SYSDATE"
             + "   AND ba.alg_locatie_key IS NULL" // geen overrrules toegestaan
             + "   AND ba.alg_district_key IS NULL"
             + "   AND prs_bedrijfadres_type IN ('V', 'P')" // P=planning stond de constraint niet toe dus is nog veel 'V'oorraad is nog niet eens zo gek
             + " ORDER BY ba.alg_locatie_key NULLS LAST, ba.alg_district_key NULLS LAST, prs_bedrijfadres_startdatum DESC";

    var oRsB = Oracle.Execute(sqlB);
    if (oRsB.Eof)
    {
        Log2File(1, sqlB);
        var tekst = "Error: No suitable technical address for company key {0} found.".format(prs_bedrijf_key);
        Log2File(1, tekst);
        // doet planrequest toch niet: marksent(XMLnode, OpdrKey, -1, tekst, cust);
        result = null;
    }
    else
    {
        result = send2address( oRsB("prs_bedrijfadres_key").Value,
                               XMLnode,
                                -1, // OpdrKey,
                                {
                                    sender: "dummy",
                                    xml_content: request_xml,
                                    ordernr: "dummy"
                                }
                            );
    }
    oRsB.Close();

    if (result)
    {
        Log2File(1, "====== " + XMLnode + " done (" + toDateTimeString(new Date()) + ")");
    }
    else
    {
        Log2File(1, "====== " + XMLnode + " sending failed.");
    }
    return result;
}

// Vanuit ASP shared/send_mail.inc
function puo_sendMail(adrTo, strSubj, strBody, params)
{
    params = params || {};
    Log2File(1, "\n====== Sending e-mail (" + toDateTimeString(new Date()) + ")");

    sendMail( params.FromAddress || S("puo_fromaddress") //p_mailfrom
              , adrTo
              , strSubj
              , null // p_body
              , strBody // p_bodyhtml
              , { replyTo: params.ReplyAddress }
              )
}

// Vanuit ASP shared/send_sms.inc
function puo_sendSMS(telnr, msg)
{
    Log2File(1, "\n====== Sending SMS (" + toDateTimeString(new Date()) + ")" + (userident ? " user: " + userident : ""));
    sendSMS( telnr, msg )
}

// Vanuit ASP mgt/aut_app_test_notification.asp
function puo_sendAPP(prs_key, msg, url)
{
    Log2File(1, "\n====== Sending APP (" + toDateTimeString(new Date()) + ")" + (userident ? " user: " + userident : ""));
    return sendAPP( prs_key, msg, url, {})
}


]]>
</script>
</component>

