/* ----------------------------------------------------------------------------------------------------------------
*	
Function:	discountLineItem

Functionality:
Reduces the amount of line item by the value mentioned in discount.
Amount = (Rate * Quantity) - Discount

Deployment:
The script can be deployed on Sales Order.

Event triggering the script:
	1) validate Line.

Custom Fields:
+-----------------------------------------------------------------------------------------------------------------+
| S. No.|	Id					|	Type			|	Level	|		Description							
+-----------------------------------------------------------------------------------------------------------------+
| (1)	|	_discline			|	Currency		|	Column	|	It holds the amount to be discounted.		|

Create above custom fields with their id and type as mentioned in table.
*------------------------------------------------------------------------------------------------------------------
*/

function discountLineItem()
{
	var disc = nlapiGetCurrentLineItemValue('item', 'custcol_discline');
	if (disc == null || disc.length == 0 || isNaN(disc))
	{
		disc = 0;
	}
	
	var qty = nlapiGetCurrentLineItemValue('item', 'quantity');
	if (qty == null || qty.length == 0 || isNaN(qty))
	{
		qty = 0;
	}

	var rate = nlapiGetCurrentLineItemValue('item', 'rate');
	if (rate == null || rate.length == 0 || isNaN(rate))
	{
		rate = 0;
	}

	var amt = parseFloat( (parseFloat(rate) * parseInt(qty) ) - parseFloat(disc)) ;

	nlapiSetCurrentLineItemValue('item', 'amount', amt);
	return true;
}