<![CDATA[
/*
    $Id$

    File:       put_orders.wsf
    Calling:    cscript ..\..\..\utils\PutOrders\put_orders.wsf
    Parameters: 0: customerId
                1:
    Context:    Scheduled task
    Note:       De code verondersteld (nog) dat de current folder een cust/xxxx/tasks folder is
                Concreter: ../Oracle.udl wordt gebruikt
*/
]]>

<job id="IncludeGenExport">
  <script language="JScript" src="../wsf_shared.js"/>
  <script language="JScript" src="./puo_shared.js"/>
  <script language="JScript" src="./puo_settings.js"/>
  <script language="JScript" src="./puo_crackURL.js"/>
  <script language="JScript" src="./puo_XMLTools.js"/>
  <script language="JScript" src="./puo_base64.js"/>
  <script language="JScript" src="./puo_connector.js"/>
  <script language="JScript" src="./puo_sendfile.js"/>
  <script language="JScript" src="./puo_sendmail.js"/>
  <script language="JScript" src="./puo_sendhttp.js"/>
  <script language="JScript" src="./puo_sendsoap.js"/>
  <script language="JScript" src="./puo_sendftp.js"/>
  <script language="JScript" src="./puo_sendsms.js"/>
  <script language="JScript" src="./puo_allorders.js"/>
  <script language="JScript" src="./puo_notifications.js"/>

  <script language="JScript">

    var applicatieRun = new Date();
    var Oracle = Connect2Oracle('puo_Putorders.wsf');

    var sql = "SELECT fac_version_cust FROM fac_version";
    var oRs = Oracle.Execute(sql);
    var customerId = oRs(0).Value;
    oRs.Close();
    __Log("CustomerId: " + customerId);

    applyIni();
    var fso  = new ActiveXObject("Scripting.FileSystemObject");
    // We zijn altijd gescheduled vanuit cust/XXXX/Tasks
/* global */ var custabspath = fso.GetAbsolutePathName("../");

    Log2File(0, "===========================================================");
    Log2File(0, "PUTORDERS STARTED (" + toDateTimeString(applicatieRun) + ")");
    Log2File(2, "puo_loglevel: " + S("puo_loglevel"));

    clearDBLog();
    settings.loadSet();
    result = process();

    var endDate = new Date();
    var duration = Math.round((endDate - applicatieRun) / 10) / 100;
    Log2File(0, "PUTORDERS FINISHED ({0}, duration {1}s)".format(toDateTimeString(endDate), duration));


// FUNCTIES

    function clearDBLog()
    {
        // Als ik sowieso log in de database gooi ik alles leeg, anders alleen de lowprio regels zo die er al zijn
        sql = "DELETE FROM imp_log"
            + " WHERE imp_log_applicatie = '$PutOrders$'";
        if (S("LogDestination",0) == 1)
        {
            sql += " AND imp_log_status IN ('I','D')";
        }
        Oracle.Execute(sql);
    }

    function process()
    {
        Log2File(2, "*> process");
        var result = {message: "", success: false};
        try
        {
            sendAllOrders();
            sendNotification();
            cleanPopup();
            result.success = true;
        }
        catch(e)
        {
            Log2File(0, "Error in process: " + e.description);
            result.message = "Error in process: " + e.description;
        }
        return result;
    }

  </script>
</job>