<?xml version="1.0"?>
<component>
<?component error="true" debug="true"?>
<registration
	description="custfunctions"
	progid="custfunction.wsc"
	version="1.00"
	classid="{4F51571C-1DFC-4769-B8DD-37B356378F12}"
>
</registration>

<public>

<!-- properties -->
	<property name="Oracle">
		<put/>
	</property>
	<property name="__Log">
		<put/>
	</property>
	<property name="__DoLog">
		<put/>
	</property>
	<property name="safe">
		<put/>
	</property>

<!-- methods -->
	<method name="bes_punch_receive">
		<PARAMETER name="RequestForm"/>
		<PARAMETER name="bes_srtdeel_key"/>
		<PARAMETER name="item"/>
	</method>
</public>

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

/*	properties	*/
function put_Oracle(newValue)	{Oracle		= newValue};
function put___Log(newValue)	{__Log		= newValue};
function put___DoLog(newValue)	{__DoLog	= newValue};
function put_safe(newValue)	    {safe		= newValue};

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

    File:   SUTFcustfunction.wsc

*/

/* Dit zijn de enige drie functies die je mag gebruiken */
var Oracle;
var __Log;
var __DoLog;
var safe;

bes_punch_receive = function (RequestForm, bes_srtdeel_key, item, pResult)
{
  var result = {orderurl: ""};
  sql = "SELECT sd.prs_bedrijf_key FROM bes_srtdeel sd WHERE sd.bes_srtdeel_key = " + bes_srtdeel_key;
  oRs = Oracle.Execute(sql);
  bedr_key = oRs("prs_bedrijf_key").value;

  function punchNVL(nm, n, def)
  {
    nm = nm.replace('#', n);
    if (RequestForm(nm).Count() == 0)
        return def;
    if (RequestForm(nm) == "")
        return def;
    return RequestForm(nm)(1);
  };

  // Alleen voor leverancier Huuskes uitvoeren (prs_bedrijf_key = 2701)
  // Alleen voor eerste item de leverdatum en bestellingid opvragen. Is toch voor elk item identiek.
  if (bedr_key == 2701 && item == 1)
  {
    var bestellingid = punchNVL("NEW_ITEM-CUST_FIELD2[#]", item, "Onbekend");
    var leverdatum = punchNVL("NEW_ITEM-CUST_FIELD3[#]", item, "Onbekend");
    if (leverdatum != "Onbekend")
    {
      sql = "SELECT TO_DATE(" + safe.quoted_sql(leverdatum) + ", 'dd-mm-yyyy') leverdatum FROM DUAL";
      oRs = Oracle.Execute(sql);
      leverdatum = oRs("leverdatum").value;
      result.orderurl = "&leverdatum=" + (new Date(leverdatum)).getTime();
    }

    if (bestellingid != "Onbekend")
      result.flex_defaults = "Huuskes ID=" + bestellingid;
  }
  return result;
}

]]>
</script>
</component>
