blue
02/08/2021, 5:17 AMMaal Dai
02/09/2021, 1:15 AMfunction amtinWordsAfterSubmit(type)
{
var Rec = nlapiGetRecordId();
var rectype = nlapiGetRecordType();
var InvRec = nlapiLoadRecord(rectype,Rec);
var TotalAmount;
var currency = InvRec.getFieldValue('currency')
nlapiLogExecution('DEBUG', 'after Submit', 'currency=' + currency);
if(type==='customerpayment'){
TotalAmount = InvRec.getFieldValue('payment');
} else {
TotalAmount = InvRec.getFieldValue('total');
}
nlapiLogExecution('DEBUG', 'after Submit', 'TotalAmount=' + TotalAmount);
if (TotalAmount == '0')
{
if(currency == '1')
{
var ZeroWord = 'Nepali Rupees Zero Only';
}
else if(currency == '2')
{
var ZeroWord = 'USD. Zero Only';
}
else if(currency == '3')
{
var ZeroWord = 'CAD. Zero Only';
}
else if(currency == '4')
{
var ZeroWord ='Euro. Zero Only';
}
else if(currency == '5')
{
var ZeroWord ='GBP. Zero Only';
}
}
else
{
var amtstr = toWordsFunc(TotalAmount,currency);
var v = 0;
if(currency == '1')
{
v = amtstr.search('And');
if (v != -1)
{
amtstr = amtstr + 'Paisa ';
}
amtstr = amtstr + 'Only';
var Vatstring = amtstr;
}
else if(currency == '2')
{
v = amtstr.search('And');
if (v != -1)
{
amtstr = amtstr + 'Cents ';
}
amtstr = amtstr + 'Only';
var Vatstring = amtstr;
}
else if(currency == '3')
{
v = amtstr.search('And');
if (v != -1)
{
amtstr = amtstr + 'Cents ';
}
amtstr = amtstr + 'Only';
var Vatstring = amtstr;
}
else if(currency == '4')
{
v = amtstr.search('And');
if (v != -1)
{
amtstr = amtstr + 'Pence ';
}
amtstr = amtstr + 'Only';
var Vatstring = amtstr;
}
else if(currency == '5')
{
v = amtstr.search('And');
if (v != -1)
{
amtstr = amtstr + 'Penny ';
}
amtstr = amtstr + 'Only';
var Vatstring = amtstr;
}
//To Display the Amount in words
}
InvRec.setFieldValue('custbody_amtwords', Vatstring);
nlapiLogExecution('DEBUG', 'after Submit', 'Amt in words=' + Vatstring);
nlapiSubmitField(rectype,Rec,'custbody_amtwords',Vatstring)
//var id = nlapiSubmitRecord(InvRec,true,true);
//nlapiLogExecution('DEBUG', 'after Submit', 'id->=' + id);
}
function toWordsFunc(s,currency)
{
nlapiLogExecution('DEBUG', 'after Submit', 'currency in function is->=' + currency);
// var str='Rs.'
if(currency == '1')
{
var str='Nepali Rupees '
}
else if(currency == '2')
{
var str='USD.'
}
else if(currency == '4')
{
var str='Euro.'
}
else if(currency == '5')
{
var str='GBP.'
}
else if(currency == '3')
{
var str='CAD.'
}
nlapiLogExecution('DEBUG', 'after Submit', 'str is->= ' + str);
var th = new Array ('Crore ','Lakhs ','Thousand ','Hundred ');
// uncomment this line for Nepali Number System
//var th = new Array('Billion ','Million ','Thousand ','Hundred ');
// uncomment this line for English Number System
// var th = ['','thousand','million', 'milliard','billion'];
//var dg = new Array ('1000000000','1000000','1000','100');
var dg = new Array ('10000000','100000','1000','100');
var dem=s.substr(s.lastIndexOf('.')+1)
//lastIndexOf(".")
//alert(dem)
s=parseInt(s)
//alert('passed value'+s)
var d
var n1,n2
while(s>=100)
{
for(var k=0;k<4;k++)
{
//alert('s ki value'+s)
d=parseInt(s/dg[k])
//alert('d='+d)
if(d>0)
{
if(d>=20)
{
//alert ('in 2nd if ')
n1=parseInt(d/10)
//alert('n1'+n1)
n2=d%10
//alert('n2'+n2)
printnum2(n1)
printnum1(n2)
}
else
printnum1(d)
str=str+th[k]
}
s=s%dg[k]
}
}
if(s>=20)
{
n1=parseInt(s/10)
n2=s%10
}
else
{
n1=0
n2=s
}
printnum2(n1)
printnum1(n2)
if(dem>0)
{
decprint(dem)
}
return str
function decprint(nm)
{
// alert('in dec print'+nm)
if(nm>=20)
{
n1=parseInt(nm/10)
n2=nm%10
}
else
{
n1=0
n2=parseInt(nm)
}
//alert('n2=='+n2)
str=str+'And '
printnum2(n1)
printnum1(n2)
}
function printnum1(num1)
{
//alert('in print 1'+num1)
switch(num1)
{
case 1:str=str+'One '
break;
case 2:str=str+'Two '
break;
case 3:str=str+'Three '
break;
case 4:str=str+'Four '
break;
case 5:str=str+'Five '
break;
case 6:str=str+'Six '
break;
case 7:str=str+'Seven '
break;
case 8:str=str+'Eight '
break;
case 9:str=str+'Nine '
break;
case 10:str=str+'Ten '
break;
case 11:str=str+'Eleven '
break;
case 12:str=str+'Twelve '
break;
case 13:str=str+'Thirteen '
break;
case 14:str=str+'Fourteen '
break;
case 15:str=str+'Fifteen '
break;
case 16:str=str+'Sixteen '
break;
case 17:str=str+'Seventeen '
break;
case 18:str=str+'Eighteen '
break;
case 19:str=str+'Nineteen '
break;
}
}
function printnum2(num2)
{
// alert('in print 2'+num2)
switch(num2)
{
case 2:str=str+'Twenty '
break;
case 3:str=str+'Thirty '
break;
case 4:str=str+'Forty '
break;
case 5:str=str+'Fifty '
break;
case 6:str=str+'Sixty '
break;
case 7:str=str+'Seventy '
break;
case 8:str=str+'Eighty '
break;
case 9:str=str+'Ninety '
break;
case 10: str=str+ 'Hundred'
break;
}
// alert('str in loop2'+str)
}
}
blue
02/09/2021, 1:21 AMMaal Dai
02/09/2021, 1:22 AM