<?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[

/*
   $Revision$
   $Id$
*/

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

/* 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: ""};
  var sql = "SELECT sd.prs_bedrijf_key FROM bes_srtdeel sd WHERE sd.bes_srtdeel_key = " + bes_srtdeel_key;
  var oRs = Oracle.Execute(sql);
  var bedr_key = oRs("prs_bedrijf_key").value;
  oRs.Close();

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

  // Alleen voor leverancier Manutan uitvoeren
  if (bedr_key == 3981)
  {
    //var detail_url = punchNVL("NEW_ITEM-ATTACHMENT[#]", item, "Onbekend");
    //if (detail_url != "Onbekend")
    //{
    //  sql = "UPDATE bes_srtdeel"
    //      + "   SET bes_srtdeel_details_loc = " + safe.quoted_sql(detail_url)
    //      + " WHERE bes_srtdeel_key = " + bes_srtdeel_key;
    //  Oracle.Execute(sql);
    //}

    //var leverdatum = punchNVL("NEW_ITEM-CUST_FIELD1[#]", item, "Onbekend");
    //if (leverdatum != "Onbekend")
    //{
    //  sql = "SELECT TO_DATE(" + safe.quoted_sql(leverdatum) + ", 'yyyymmdd') leverdatum FROM DUAL";
    //  var oRs = Oracle.Execute(sql);
    //  leverdatum = oRs("leverdatum").value;
    //  oRs.Close();
    //  result.orderurl = "&leverdatum=" + (new Date(leverdatum)).getTime();
    //}

    // BTW
    var btw_perc = punchNVL("NEW_ITEM-CUST_FIELD3[#]", item, "Onbekend");
    __Log('BTW-PERCENTAGE: CUST_FIELD3[' + item + ']= ' + btw_perc); 
    if (btw_perc != 'Onbekend')
    {
       sql = "UPDATE bes_srtdeel SET bes_srtdeel_btw = ROUND(" + parseFloat(btw_perc) + ") WHERE bes_srtdeel_key = " + bes_srtdeel_key;
       Oracle.Execute(sql);
    }
  }
  // Alleen voor leverancier Bechtle uitvoeren
  if (bedr_key == 6853)
  {
    // BTW
    var btw_perc = punchNVL("NEW_ITEM-CUST_FIELD1[#]", item, "Onbekend");
    __Log('BTW-PERCENTAGE: CUST_FIELD1[' + item + ']= ' + btw_perc); 
    if (btw_perc != 'Onbekend')
    {
       sql = "UPDATE bes_srtdeel SET bes_srtdeel_btw = ROUND(" + parseFloat(btw_perc) + ") WHERE bes_srtdeel_key = " + bes_srtdeel_key;
       Oracle.Execute(sql);
    }
  }
  // Alleen voor leverancier Technische Unie uitvoeren
  if (bedr_key == 8016)
  {
    // BTW
    var btw_perc = punchNVL("NEW_ITEM-CUST_FIELD4[#]", item, "Onbekend");
    __Log('BTW-PERCENTAGE: CUST_FIELD4[' + item + ']= ' + btw_perc); 
    if (btw_perc != 'Onbekend')
    {
       sql = "UPDATE bes_srtdeel SET bes_srtdeel_btw = ROUND(" + parseFloat(btw_perc) + ") WHERE bes_srtdeel_key = " + bes_srtdeel_key;
       Oracle.Execute(sql);
    }
  }
  // Alleen voor leverancier Jos ten Berg uitvoeren
  if (bedr_key == 8060)
  {
    // BTW
    var btw_perc = punchNVL("NEW_ITEM-CUST_FIELD1[#]", item, "Onbekend");
    __Log('BTW-PERCENTAGE: CUST_FIELD1[' + item + ']= ' + btw_perc); 
    if (btw_perc != 'Onbekend')
    {
       sql = "UPDATE bes_srtdeel SET bes_srtdeel_btw = ROUND(" + parseFloat(btw_perc) + ") WHERE bes_srtdeel_key = " + bes_srtdeel_key;
       Oracle.Execute(sql);
    }
  }
  return result;
}

]]>
</script>
</component>
