Best JavaScript code snippet using ava
AVA_ReconcileHistory.js
Source:AVA_ReconcileHistory.js
1/******************************************************************************************2 Script Name - AVA_ReconcileHistory.js3 Company - Avalara Technologies Pvt Ltd.4******************************************************************************************/56{7 var recordIdArray, recordObjArray, AVA_PrevFlag, AVA_NextFlag; 8 var AVA_EndPage, AVA_LineCount, MultiCurr;9 10 //Batch Info Variables11 var BatchId, BatchName, StartDate, EndDate, LastDocCode;12 var Total = only_AVA = only_NS = only_CR = AVA_NS = NS_CR = AVA_CR = AVA_NS_CR = Reconciled = 0;13 14 var NSIdsText, NSIdsArray, NS_CreatedDocField, NS_NextDocField, NSIdsCurrText = '', CRIdsText, CRIdsArray, CR_CreatedDocField, CR_NextDocField, CRIdsCurrText = '', fields, values;15 16 var MinUsage = 300;17 18}1920function AVA_ReconcileTransactions(request, response)21{22 if(AVA_CheckService('TaxSvc') == 0 && AVA_CheckSecurity( 9 ) == 0)23 {24 if(request.getMethod() == 'GET')25 {26 var AVA_TransactionForm = nlapiCreateForm('Create Reconciliation Batch');27 AVA_TransactionForm.setScript('customscript_avareconcilelist_client');28 AVA_TransactionForm.setTitle('Create Reconciliation Batch');29 30 var DateFrom = AVA_TransactionForm.addField('ava_datefrom', 'date', 'Starting Date');31 DateFrom.setDefaultValue(nlapiGetContext().getSetting('SESSION', 'DateFrom'));32 DateFrom.setMandatory(true);33 34 var DateTo = AVA_TransactionForm.addField('ava_dateto', 'date', 'Ending Date');35 DateTo.setDefaultValue(nlapiGetContext().getSetting('SESSION', 'DateTo'));36 DateTo.setMandatory(true);37 38 var DateFormat = AVA_TransactionForm.addField('ava_dateformat', 'text', 'Date Format');39 DateFormat.setDefaultValue(nlapiGetContext().getSetting('PREFERENCE', 'DATEFORMAT'));40 DateFormat.setMandatory(true);41 DateFormat.setDisplayType('hidden');42 43 var BatchName = AVA_TransactionForm.addField('ava_batchname', 'text', 'Batch Name');44 BatchName.setMandatory(true);45 46 var BatchHelp = AVA_TransactionForm.addField('ava_batchhelp', 'help', 'NOTE: For better performance, please select a date range which has got less than 1000 transactions.');47 BatchHelp.setLayoutType('outsidebelow');48 49 AVA_TransactionForm.addSubmitButton('Submit');50 //AVA_TransactionForm.addPageLink('breadcrumb', 'Create Batch', nlapiResolveURL('SUITELET', 'customscript_avareconcilelist_suitelet', 'customdeploy_avareconcilelist'));51 AVA_TransactionForm.addPageLink('crosslink', 'View Reconciliation Results', nlapiResolveURL('SUITELET', 'customscript_ava_reconciliation_suitelet', 'customdeploy_ava_reconcileresult'));52 response.writePage(AVA_TransactionForm);53 }54 else55 {56 try57 {58 var record = nlapiCreateRecord('customrecord_avareconcilebatch');59 60 record.setFieldValue('custrecord_ava_batchname', request.getParameter('ava_batchname')); 61 record.setFieldValue('custrecord_ava_batchstartdate', request.getParameter('ava_datefrom')); 62 record.setFieldValue('custrecord_ava_batchenddate', request.getParameter('ava_dateto')); 63 record.setFieldValue('custrecord_ava_batchstatus', 0); 64 record.setFieldValue('custrecord_ava_batchprogress', 0);65 66 var recId = nlapiSubmitRecord(record, false); 67 68 var filters = new Array();69 filters[0] = new nlobjSearchFilter('custrecord_ava_batchstatus', null, 'lessthan', 2);70 var searchResult3 = nlapiSearchRecord('customrecord_avareconcilebatch', null, filters, null);71 if(searchResult3 != null && searchResult3.length == 1)72 {73 nlapiScheduleScript('customscript_ava_reconcileavatax_sched','customdeploy_reconciletax_deploy1'); 74 }75 76 nlapiSetRedirectURL('SUITELET', 'customscript_ava_reconciliation_suitelet', 'customdeploy_ava_reconcileresult');77 }78 catch( e )79 {80 var code = e instanceof nlobjError ? e.getStackTrace() : e.description;81 var xml = '<?xml version="1.0" encoding="utf-8" ?>'+82 '<error>'+83 '<code>'+84 code +85 '</code>'+86 '</error>';87 response.write( xml ); 88 }89 } 90 }91}9293//Client side Save function for Suitelet AVA_ReconcileTransactions94function AVA_BatchSaveRecord()95{96 var BatchName = nlapiGetFieldValue('ava_batchname');97 var StartDate = nlapiGetFieldValue('ava_datefrom');98 var EndDate = nlapiGetFieldValue('ava_dateto');99 var DateFormat = nlapiGetFieldValue('ava_dateformat');100101 if(StartDate.length == 0)102 {103 alert('Select Starting Date');104 return false;105 }106 107 if(EndDate.length == 0)108 {109 alert('Select Ending Date');110 return false;111 }112 113 if(nlapiGetFieldValue('ava_batchname').length == 0)114 {115 alert('Enter a Batch Name');116 return false;117 }118119 StartDate = new Date(AVA_FormatDate(DateFormat,StartDate));120 EndDate = new Date(AVA_FormatDate(DateFormat,EndDate));121 122 if(EndDate < StartDate)123 {124 alert('Ending Date should be greater than or equal to Start Date');125 return false;126 }127 128 var response = nlapiRequestURL(nlapiResolveURL('SUITELET', 'customscript_ava_recordload_suitelet', 'customdeploy_ava_recordload') + '&type=customrecord_avaconfig', null, null );129 if(response.getBody() == '0') // If Config Record exists130 {131 var response1 = nlapiRequestURL(nlapiResolveURL('SUITELET', 'customscript_ava_recordload_suitelet', 'customdeploy_ava_recordload') + '&type=customrecord_avareconcilebatch&batchname=' + BatchName, null, null );132 if(response1.getBody() == '0') // Batch name already exists133 {134 alert('Batch Name already Exists. Enter a new Batch Name');135 document.forms['main_form'].ava_batchname.focus();136 return false;137 }138 return true;139 }140 else141 {142 alert('AvaTax Configuration not setup. Details missing');143 return false;144 }145}146147148function AVA_ReconcileData()149{150 nlapiLogExecution('Debug','AVA_ReconcileData Script successfully called','Batch Id: ' + nlapiGetContext().getSetting('SCRIPT', 'custscript_ava_reconcilebatchid'));151 152 var scriptContext = nlapiGetContext();153 154 var filters = new Array();155 filters[0] = new nlobjSearchFilter('custrecord_ava_batchstatus', null, 'lessthan', 2);156 157 var searchResult = nlapiSearchRecord('customrecord_avareconcilebatch', null, filters, null);158 159 for(var i = 0; nlapiGetContext().getRemainingUsage() > MinUsage && searchResult != null && i < searchResult.length ; i++)160 { 161 BatchId = searchResult[i].getId();162 var BatchStatus = nlapiLookupField('customrecord_avareconcilebatch', BatchId, 'custrecord_ava_batchstatus');163 // Batch Phases:164 // '' or null = processing not started or none of the phase got completed.165 // 0 = First phase completed, i.e: Reconciled Avatax side records (AvaTax + NetSuite + CustomRecord)166 // 1 = Second phase completed, i.e: Reconciled Netsuite side records (NetSuite + CustomRecord)167 // 2 = Third phase completed, i.e: Reconciled Netsuite side Custom Records (Custom Record)-Reconciliation Completed 168 169 170 // Batch Statuses:171 // 0 = not started / In Queue172 // 1 = In Progress173 // 2 = Completed174 // 3 = Delete175 // 4 = Error 176 177 while(BatchStatus == 0 || BatchStatus == 1)178 { 179 var BatchPhase = nlapiLookupField('customrecord_avareconcilebatch', BatchId, 'custrecord_ava_batchphase'); 180 nlapiLogExecution('Debug', 'AVA_ReconcileData: B\atchPhase: ', BatchPhase);181 if(scriptContext.getRemainingUsage() > MinUsage && BatchPhase != 2)182 { 183 switch(BatchPhase)184 {185 case 0:186 case '0': 187 nlapiLogExecution('Debug', 'Calling AVA_GetNetsuiteTransactions', '');188 AVA_GetNetsuiteTransactions();189 nlapiLogExecution('Debug', 'Called AVA_GetNetsuiteTransactions', '');190 break;191 192 case 1: 193 case '1':194 nlapiLogExecution('Debug', 'Calling AVA_GetHeaderCustomRecordsData', '');195 AVA_GetHeaderCustomRecordsData();196 nlapiLogExecution('Debug', 'Called AVA_GetHeaderCustomRecordsData', '');197 break; 198 199 default:200 nlapiLogExecution('Debug', 'Calling AVA_GetAvataxTransactions', '');201 AVA_GetAvataxTransactions('Committed');202 nlapiLogExecution('Debug', 'Called AVA_GetAvataxTransactions', '');203 break; 204 }205 }206 else207 {208 nlapiLogExecution('Debug', 'In else: ', '');209 nlapiScheduleScript(scriptContext.getScriptId(), scriptContext.getDeploymentId());210 break;211 }212 213 BatchStatus = nlapiLookupField('customrecord_avareconcilebatch', BatchId, 'custrecord_ava_batchstatus');214 }215 }216 if (nlapiGetContext().getRemainingUsage() > RecalcMinUsage)217 {218 var filters1 = new Array();219 filters1[0] = new nlobjSearchFilter('custrecord_ava_batchstatus', null, 'lessthan', 2);220 var searchResult2 = nlapiSearchRecord('customrecord_avareconcilebatch', null, filters, null);221 if(searchResult2 != null)222 {223 AVA_ReconcileData();224 }225 }226}227228function AVA_GetHeaderCustomRecordsData()229{230 var MultiCurrBatch, AVA_ResultFlag = true;231 232 while(nlapiGetContext().getRemainingUsage() > MinUsage && AVA_ResultFlag == true)233 {234 AVA_LoadBatchValues();235 236 var filters = new Array();237 filters[0] = new nlobjSearchFilter('custrecord_ava_documentdate', null, 'within', StartDate, EndDate);238 filters[1] = new nlobjSearchFilter('custrecord_ava_documentstatus', null, 'equalto', 3);239 240 if(NSIdsArray != null && NSIdsArray.length > 0 && NSIdsArray != 'undefined')241 {242 filters[filters.length] = new nlobjSearchFilter('custrecord_ava_documentinternalid',null, 'noneof', NSIdsArray); 243 }244 245 if(CRIdsArray != null && CRIdsArray.length > 0 && CRIdsArray != 'undefined')246 {247 filters[filters.length] = new nlobjSearchFilter('internalid', null, 'noneof', CRIdsArray);248 nlapiLogExecution('Debug','CRIdsArray Length: ', CRIdsArray.length);249 }250 251 var columns = new Array();252 columns[0] = new nlobjSearchColumn('custrecord_ava_documentinternalid');253 columns[1] = new nlobjSearchColumn('custrecord_ava_documenttype');254 columns[2] = new nlobjSearchColumn('custrecord_ava_documentdate');255 columns[3] = new nlobjSearchColumn('custrecord_ava_documentstatus');256 columns[4] = new nlobjSearchColumn('custrecord_ava_totalamount');257 columns[5] = new nlobjSearchColumn('custrecord_ava_totaldiscount');258 columns[6] = new nlobjSearchColumn('custrecord_ava_totalnontaxable');259 columns[7] = new nlobjSearchColumn('custrecord_ava_totaltaxable');260 columns[8] = new nlobjSearchColumn('custrecord_ava_totaltax');261 columns[9] = new nlobjSearchColumn('custrecord_ava_taxcalculationdate');262 columns[10] = new nlobjSearchColumn('custrecord_ava_documentid');263 columns[11] = new nlobjSearchColumn('custrecord_ava_multicurrency');264 columns[12] = new nlobjSearchColumn('custrecord_ava_exchangerate');265 266 var searchResult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, columns);267 268 if(searchResult != null)269 {270 nlapiLogExecution('Debug','CRs Search Length: ', searchResult.length);271 for(var k=0; nlapiGetContext().getRemainingUsage() > MinUsage && k < searchResult.length ; k++)272 { 273 var CR_RecordId = searchResult[k].getId();274 nlapiLogExecution('Debug','CR_RecordId: ', CR_RecordId);275 var BatchChildRecord = nlapiCreateRecord('customrecord_avareconcilebatchrecords');276 277 //Setting in AVATAXHEADERDETAILS Custom record Data in AVARECONCILEBATCHRECORDS custom record278 BatchChildRecord.setFieldValue('custrecord_ava_batchid', BatchId);279 BatchChildRecord.setFieldValue('custrecord_ava_batchdoctype', searchResult[k].getValue('custrecord_ava_documenttype'));280 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxcrdoctype', searchResult[k].getValue('custrecord_ava_documenttype'));281 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxcrdocdate', searchResult[k].getValue('custrecord_ava_documentdate'));282 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxcrdocstatus', searchResult[k].getValue('custrecord_ava_documentstatus'));283 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxtotalamount', searchResult[k].getValue('custrecord_ava_totalamount'));284 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxtotaldiscount', searchResult[k].getValue('custrecord_ava_totaldiscount')); 285 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotalexemption', searchResult[k].getValue('custrecord_ava_totalnontaxable')); 286 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotaltaxable', searchResult[k].getValue('custrecord_ava_totaltaxable')); 287 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotaltax', searchResult[k].getValue('custrecord_ava_totaltax')); 288 var MultiCurr = searchResult[k].getValue('custrecord_ava_multicurrency');289 BatchChildRecord.setFieldValue('custrecord_ava_batchmulticurrency', MultiCurr); 290 if(MultiCurr == 'T')291 {292 MultiCurrBatch = 'T';293 }294 295 if(searchResult[k].getValue('custrecord_ava_exchangerate') != null && searchResult[k].getValue('custrecord_ava_exchangerate').length>0)296 {297 var TotalAmount = parseFloat(searchResult[k].getValue('custrecord_ava_totalamount')) / parseFloat(searchResult[k].getValue('custrecord_ava_exchangerate'));298 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxtotalamountfc', TotalAmount); 299 var TotalTax = parseFloat(searchResult[k].getValue('custrecord_ava_totaltax')) / parseFloat(searchResult[k].getValue('custrecord_ava_exchangerate'));300 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotaltaxfc', TotalTax); 301 }302 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxdate', searchResult[k].getValue('custrecord_ava_taxcalculationdate')); 303 BatchChildRecord.setFieldValue('custrecord_ava_statusflag', 3);//Only Custom Record304 var BatchRecId = nlapiSubmitRecord(BatchChildRecord, false);305 only_CR++; 306 307 var TempDocArray = CRIdsText;308 if(TempDocArray != null && TempDocArray.length > 3500)309 { 310 CR_NextDocField = CR_CreatedDocField;311 CRIdsCurrText += CR_RecordId + ',';312 CR_NextDocField = (CR_NextDocField=='custrecord_ava_createddocids1')? 'custrecord_ava_createddocids2' : ((CR_NextDocField == 'custrecord_ava_createddocids2') ? 'custrecord_ava_createddocids3': 'custrecord_ava_createddocids4');313 }314 else315 {316 CRIdsText += CR_RecordId + ',';317 } 318 }319 320 //Submit progress details into Batch321 fields = new Array();322 values = new Array();323 324 fields[0] = 'custrecord_ava_onlycr';325 values[0] = only_CR;326 327 if(CRIdsText != '')328 {329 fields[fields.length] = CR_CreatedDocField;330 values[values.length] = CRIdsText; 331 }332 333 if(CRIdsCurrText != '')334 {335 fields[fields.length] = CR_NextDocField;336 values[values.length] = CRIdsCurrText; 337 }338 339 if(MultiCurrBatch == 'T')340 {341 fields[fields.length] = 'custrecord_ava_multicurrencybatch';342 values[values.length] = 'T';343 }344345 nlapiSubmitField('customrecord_avareconcilebatch',BatchId,fields,values,false); 346 }347 else348 {349 AVA_ResultFlag = false;350 } 351 }352 353 //Third phase is complete354 if(AVA_ResultFlag == false)355 { 356 fields = new Array();357 values = new Array();358 359 fields[fields.length] = 'custrecord_ava_batchphase';360 values[values.length] = 2;361 362 fields[fields.length] = 'custrecord_ava_batchstatus';363 values[values.length] = 2;364 365 Total = parseFloat(only_AVA) + parseFloat(only_NS);366 Total += parseFloat(only_CR) + parseFloat(AVA_NS);367 Total += parseFloat(AVA_CR) + parseFloat(NS_CR);368 Total += parseFloat(AVA_NS_CR) + parseFloat(Reconciled);369 370 fields[fields.length] = 'custrecord_ava_totalrecords';371 values[values.length] = Total;372 373 fields[fields.length] = 'custrecord_ava_batchprogress';374 values[values.length] = 100; 375 376 nlapiSubmitField('customrecord_avareconcilebatch', BatchId, fields, values);377 }378 379 380}381382383function AVA_GetNetsuiteTransactions()384{385 var MultiCurrBatch, AVA_ResultFlag = true;386 387 while(nlapiGetContext().getRemainingUsage() > MinUsage && AVA_ResultFlag == true)388 {389 AVA_LoadBatchValues();390 391 var TypeArray = new Array('CustInvc','CashSale','CustCred','CashRfnd');392 var filters = new Array();393 filters[0] = new nlobjSearchFilter('mainline', null, 'is', 'T');394 filters[1] = new nlobjSearchFilter('type', null, 'anyof', TypeArray);395 filters[2] = new nlobjSearchFilter('trandate', null, 'within', StartDate, EndDate);396 filters[3] = new nlobjSearchFilter('voided', null, 'is', 'F');397 filters[4] = new nlobjSearchFilter('memorized', null, 'is', 'F');398 399 if(NSIdsArray != null && NSIdsArray.length > 0 && NSIdsArray != 'undefined')400 {401 filters[5] = new nlobjSearchFilter('internalid', null, 'noneof', NSIdsArray);402 }403 404 var searchResult = nlapiSearchRecord('transaction', null, filters, null);405 406 if(searchResult != null && searchResult.length > 0)407 {408 nlapiLogExecution('DEBUG','AVA_GetNetsuiteTransactions: searchResult:' , searchResult.length);409 for(var k=0; nlapiGetContext().getRemainingUsage() > MinUsage && k < searchResult.length; k++)410 {411 try412 {413 var DocType, NS_RecordType;414 var NS_Record = nlapiLoadRecord(searchResult[k].getRecordType(), searchResult[k].getId());415 416 var BatchChildRecord = nlapiCreateRecord('customrecord_avareconcilebatchrecords');417 418 //Setting in Netsuite Data in the custom record419 //BatchChildRecord.setFieldValue('custrecord_ava_batchid', BatchId);420 BatchChildRecord.setFieldValue('custrecord_ava_reconcilebatchname', BatchName);421 BatchChildRecord.setFieldValue('custrecord_ava_batchdocno', searchResult[k].getId());422 423 NS_RecordType = (NS_Record.getFieldValue('type') == 'custinvc' || NS_Record.getFieldValue('type') == 'cashsale') ? 1 : 2424 DocType = (NS_Record.getFieldValue('type') == 'custinvc') ? 1 : ((NS_Record.getFieldValue('type') == 'cashsale') ? 3 : ((NS_Record.getFieldValue('type') == 'cashrfnd') ? 4 : 5));425 426 var Multiplier = (NS_RecordType == 1)? 1 : -1;427 428 BatchChildRecord.setFieldValue('custrecord_ava_batchdoctype', DocType);429 BatchChildRecord.setFieldValue('custrecord_ava_netsuitedoctyp', NS_RecordType);430 431 var MultiCurr = (NS_Record.getFieldValue('isbasecurrency') == 'F') ? 'T' : 'F';432 BatchChildRecord.setFieldValue('custrecord_ava_batchmulticurrency', MultiCurr);433 434 if(MultiCurr == 'T')435 {436 MultiCurrBatch = 'T';437 }438 439 BatchChildRecord.setFieldValue('custrecord_ava_netsuitedocdate', NS_Record.getFieldValue('trandate'));440 441 var subtotal = (NS_Record.getFieldValue('subtotal') == null) ? 0 : nlapiFormatCurrency(NS_Record.getFieldValue('subtotal'));442 var shipcost = (NS_Record.getFieldValue('shippingcost') == null) ? 0 : nlapiFormatCurrency(NS_Record.getFieldValue('shippingcost'));443 var handlingcost = (NS_Record.getFieldValue('handlingcost') == null) ? 0 : nlapiFormatCurrency(NS_Record.getFieldValue('handlingcost'));444 var giftcert = (NS_Record.getFieldValue('giftcertapplied') == null) ? 0 : nlapiFormatCurrency(NS_Record.getFieldValue('giftcertapplied'));445 var exchangeRate = NS_Record.getFieldValue('exchangerate');446 447 var TotalAmount = parseFloat(subtotal) + parseFloat(shipcost) + parseFloat(handlingcost) + parseFloat(giftcert);448 BatchChildRecord.setFieldValue('custrecord_ava_netsuitetotalamountfc', parseFloat(TotalAmount * Multiplier));449 450 TotalAmount = parseFloat(nlapiFormatCurrency(subtotal*exchangeRate)) + parseFloat(nlapiFormatCurrency(shipcost*exchangeRate)) + parseFloat(nlapiFormatCurrency(handlingcost*exchangeRate)) + parseFloat(nlapiFormatCurrency(giftcert*exchangeRate));451 BatchChildRecord.setFieldValue('custrecord_ava_netsuitetotalamount', nlapiFormatCurrency(TotalAmount * Multiplier));452 453 var Discount = (NS_Record.getFieldValue('discountamount')== null) ? 0 : NS_Record.getFieldValue('discountamount');454 BatchChildRecord.setFieldValue('custrecord_ava_netsuitetotaldiscount', Discount);455 456 var TaxTotal = (NS_Record.getFieldValue('taxtotal')== null) ? 0 : nlapiFormatCurrency(NS_Record.getFieldValue('taxtotal'));457 BatchChildRecord.setFieldValue('custrecord_ava_netsuitetotaltaxfc', parseFloat(TaxTotal*Multiplier));458 459 TaxTotal = parseFloat(nlapiFormatCurrency(TaxTotal * exchangeRate));460 BatchChildRecord.setFieldValue('custrecord_ava_netsuitetotaltax', nlapiFormatCurrency(TaxTotal * Multiplier));461 462 //setting in Header Detail Custom record Data in Batch Custom record463 464 var NS_CRExist = 'T', CR_RecordId;465 var custfilter = new Array();466 custfilter[0] = new nlobjSearchFilter('custrecord_ava_documentinternalid', null, 'is', searchResult[k].getId());467 custfilter[1] = new nlobjSearchFilter('custrecord_ava_documentstatus', null, 'is', 3);468 469 var columns = new Array();470 columns[0] = new nlobjSearchColumn('custrecord_ava_documentno');471 columns[1] = new nlobjSearchColumn('custrecord_ava_documenttype');472 columns[2] = new nlobjSearchColumn('custrecord_ava_documentdate');473 columns[3] = new nlobjSearchColumn('custrecord_ava_documentstatus');474 columns[4] = new nlobjSearchColumn('custrecord_ava_totalamount');475 columns[5] = new nlobjSearchColumn('custrecord_ava_totaldiscount');476 columns[6] = new nlobjSearchColumn('custrecord_ava_totalnontaxable');477 columns[7] = new nlobjSearchColumn('custrecord_ava_totaltaxable');478 columns[8] = new nlobjSearchColumn('custrecord_ava_totaltax');479 columns[9] = new nlobjSearchColumn('custrecord_ava_taxcalculationdate');480 columns[10] = new nlobjSearchColumn('custrecord_ava_multicurrency');481 columns[11] = new nlobjSearchColumn('custrecord_ava_exchangerate');482 483 var searchRecords = nlapiSearchRecord('customrecord_avataxheaderdetails', null, custfilter, columns);484 485 if( searchRecords != null )486 {487 CR_RecordId = searchRecords[0].getId();488 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxcrdoctype', searchRecords[0].getValue('custrecord_ava_documenttype'));489 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxcrdocdate', searchRecords[0].getValue('custrecord_ava_documentdate'));490 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxcrdocstatus', searchRecords[0].getValue('custrecord_ava_documentstatus'));491 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxtotalamount', searchRecords[0].getValue('custrecord_ava_totalamount'));492 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxtotaldiscount', searchRecords[0].getValue('custrecord_ava_totaldiscount')); 493 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotalexemption', searchRecords[0].getValue('custrecord_ava_totalnontaxable')); 494 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotaltaxable', searchRecords[0].getValue('custrecord_ava_totaltaxable')); 495 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotaltax', searchRecords[0].getValue('custrecord_ava_totaltax')); 496 BatchChildRecord.setFieldValue('custrecord_ava_batchmulticurrency', searchRecords[0].getValue('custrecord_ava_multicurrency')); 497 if(searchRecords[0].getValue('custrecord_ava_exchangerate') != null && searchRecords[0].getValue('custrecord_ava_exchangerate').length>0)498 {499 var TotalAmount = parseFloat(searchRecords[0].getValue('custrecord_ava_totalamount')) / parseFloat(searchRecords[0].getValue('custrecord_ava_exchangerate'));500 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxtotalamountfc', TotalAmount); 501 var TotalTax = parseFloat(searchRecords[0].getValue('custrecord_ava_totaltax')) / parseFloat(searchRecords[0].getValue('custrecord_ava_exchangerate'));502 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotaltaxfc', TotalTax); 503 }504 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxdate', searchRecords[0].getValue('custrecord_ava_taxcalculationdate')); 505 }506 else507 {508 NS_CRExist = 'F';509 }510 511 //set status flag in AVARECONCILEBATCHRECORDS512 if(NS_CRExist == 'F')513 {514 BatchChildRecord.setFieldValue('custrecord_ava_statusflag', 2);//Only Netsuite515 only_NS++;516 }517 else 518 {519 BatchChildRecord.setFieldValue('custrecord_ava_statusflag', 6);//Exists in Netsuite and Custom Record520 NS_CR++;521 }522 523 var BatchRecId = nlapiSubmitRecord(BatchChildRecord, false);524 525 var TempDocArray = NSIdsText;526 527 if(TempDocArray != null && TempDocArray.length > 3500)528 {529 NS_NextDocField = NS_CreatedDocField;530 NSIdsCurrText += searchResult[k].getId() + ',';531 NS_NextDocField = (NS_NextDocField=='custrecord_ava_nscreateddocids1')? 'custrecord_ava_nscreateddocids2' : ((NS_NextDocField == 'custrecord_ava_nscreateddocids2') ? 'custrecord_ava_nscreateddocids3': 'custrecord_ava_nscreateddocids4');532 }533 else534 {535 NSIdsText += searchResult[k].getId() + ',';536 } 537 538 var TempDocArray = CRIdsText;539 if(TempDocArray != null && TempDocArray.length > 3500)540 { 541 if(NS_CRExist == 'T')542 {543 CR_NextDocField = CR_CreatedDocField;544 CRIdsCurrText += CR_RecordId + ',';545 CR_NextDocField = (CR_NextDocField=='custrecord_ava_createddocids1')? 'custrecord_ava_createddocids2' : ((CR_NextDocField == 'custrecord_ava_createddocids2') ? 'custrecord_ava_createddocids3': 'custrecord_ava_createddocids4');546547 }548 }549 else550 {551 if(NS_CRExist == 'T')552 {553 CRIdsText += CR_RecordId + ',';554 }555 } 556 }557 catch(err)558 {559 nlapiLogExecution('Error','Got Error on Record Submit for Netsuite DocId: ',searchResult[k].getId());560 break;561 }562 }563 564 //Submit progress details into Batch565 fields = new Array();566 values = new Array();567 568 fields[0] = 'custrecord_ava_onlyns';569 values[0] = only_NS;570 571 fields[1] = 'custrecord_ava_nscr';572 values[1] = NS_CR;573 574 if(NSIdsText != '')575 {576 fields[fields.length] = NS_CreatedDocField;577 values[values.length] = NSIdsText; 578 }579 580 if(NSIdsCurrText != '')581 {582 fields[fields.length] = NS_NextDocField;583 values[values.length] = NSIdsCurrText; 584 }585 586 if(CRIdsText != '')587 {588 fields[fields.length] = CR_CreatedDocField;589 values[values.length] = CRIdsText; 590 }591 592 if(CRIdsCurrText != '')593 {594 fields[fields.length] = CR_NextDocField;595 values[values.length] = CRIdsCurrText; 596 }597 598 if(MultiCurrBatch == 'T')599 {600 fields[fields.length] = 'custrecord_ava_multicurrencybatch';601 values[values.length] = 'T';602 }603604 nlapiSubmitField('customrecord_avareconcilebatch',BatchId,fields,values,false);605 606 }607 else608 {609 AVA_ResultFlag = false;610 } 611 }612 613 //Second phase is complete614 if(AVA_ResultFlag == false)615 { 616 fields = new Array();617 values = new Array();618 619 fields[0] = 'custrecord_ava_batchphase';620 values[0] = 1;621 622 fields[1] = 'custrecord_ava_batchprogress';623 values[1] = 80; 624 625 nlapiSubmitField('customrecord_avareconcilebatch', BatchId, fields, values);626 }627}628629630function AVA_SplitTextField(FieldValue)631{632 var LastDocArray = new Array();633 634 LastDocArray = FieldValue.split(',');635 636 return LastDocArray;637}638639function AVA_GetAvataxTransactions(DocStatus)640{641 nlapiLogExecution('Debug', 'In AVA_GetAvataxTransactions','');642 643 var MultiCurrBatch, AVA_ResultFlag = true;644 645 nlapiSubmitField('customrecord_avareconcilebatch', BatchId, 'custrecord_ava_batchstatus', 1);646647 BatchName = nlapiLookupField('customrecord_avareconcilebatch', BatchId, 'custrecord_ava_batchname');648 649 AVA_ReadConfig('0');650 var security = AVA_TaxSecurity(AVA_AccountValue, AVA_LicenseKey);651 var headers = AVA_ReconcileTaxHeader(security);652 var soapHead = new Array();653 soapHead['Content-Type'] = 'text/xml';654 soapHead['SOAPAction'] = 'http://avatax.avalara.com/services/ReconcileTaxHistory';655656 while(nlapiGetContext().getRemainingUsage() > MinUsage && AVA_ResultFlag == true)657 {658 AVA_LoadBatchValues();659 660 var body = AVA_ReconcileTaxBody(DocStatus, LastDocCode);661 var soapPayload = AVA_GetTaxEnvelope(headers + body); 662 663 var response = nlapiRequestURL(AVA_ServiceUrl + '/tax/taxsvc.asmx' , soapPayload, soapHead);664 665 if (response.getCode() == 200)666 {667 var soapText = response.getBody();668 var soapXML = nlapiStringToXML(soapText);669 var ReconcileTaxResult = nlapiSelectNode(soapXML, "//*[name()='ReconcileTaxHistoryResult']");670 var ResultCode = nlapiSelectValue( ReconcileTaxResult, "./*[name()='ResultCode']");671672 if (ResultCode == 'Success') 673 {674 var GetTaxResult = new Array();675 GetTaxResult = nlapiSelectNodes(ReconcileTaxResult, "//*[name()='GetTaxResult']");676 677 if(GetTaxResult != null && GetTaxResult.length > 0)678 {679 nlapiLogExecution('Debug', 'GetTaxResult Length' + i, GetTaxResult.length); 680 for(var i = 0; nlapiGetContext().getRemainingUsage() > MinUsage && i < GetTaxResult.length ; i++)681 { 682 nlapiLogExecution('Debug', 'GetTaxResult : i' + i, nlapiXMLToString(GetTaxResult[i])); 683 var NS_TranExist = NS_CRExist = 'F';//flag to indicate whether a record is existing in Netsuite or not. 684 var DocType = AVA_DocType(nlapiSelectValue( GetTaxResult[i], "./*[name()='DocType']"));685 686 try687 { 688 // If DocType = SalesInvoice or ReturnInvoice on AvaTax 689 if(DocType == 2 || DocType == 6)690 {691 var BatchChildRecord = nlapiCreateRecord('customrecord_avareconcilebatchrecords');692 var NS_RecordId = nlapiSelectValue( GetTaxResult[i], "./*[name()='DocCode']");693 var CR_RecordId;694 695 //save reconcile avatax call data into custom record fields 696 //BatchChildRecord.setFieldValue('custrecord_ava_batchid', BatchId); 697 BatchChildRecord.setFieldValue('custrecord_ava_reconcilebatchname', BatchName); 698 BatchChildRecord.setFieldValue('custrecord_ava_avataxdoctype', DocType); 699 BatchChildRecord.setFieldValue('custrecord_ava_batchdoctype', DocType); 700 BatchChildRecord.setFieldValue('custrecord_ava_avataxdocdate', AVA_DateFormat(nlapiGetContext().getSetting('PREFERENCE', 'DATEFORMAT'),nlapiSelectValue( GetTaxResult[i], "./*[name()='DocDate']"))); 701 BatchChildRecord.setFieldValue('custrecord_ava_avataxdocstatus', AVA_DocumentStatus(nlapiSelectValue( GetTaxResult[i], "./*[name()='DocStatus']")));702 BatchChildRecord.setFieldValue('custrecord_ava_avataxtotalamount', nlapiSelectValue( GetTaxResult[i], "./*[name()='TotalAmount']"));703 BatchChildRecord.setFieldValue('custrecord_ava_avataxtotaldiscount', nlapiSelectValue( GetTaxResult[i], "./*[name()='TotalDiscount']"));704 BatchChildRecord.setFieldValue('custrecord_ava_avatotalexemption', nlapiSelectValue( GetTaxResult[i], "./*[name()='TotalExemption']"));705 BatchChildRecord.setFieldValue('custrecord_ava_avatotaltaxable', nlapiSelectValue( GetTaxResult[i], "./*[name()='TotalTaxable']"));706 BatchChildRecord.setFieldValue('custrecord_ava_avatotaltax', nlapiSelectValue( GetTaxResult[i], "./*[name()='TotalTax']"));707 BatchChildRecord.setFieldValue('custrecord_ava_avataxdate', AVA_DateFormat(nlapiGetContext().getSetting('PREFERENCE', 'DATEFORMAT'),nlapiSelectValue( GetTaxResult[i], "./*[name()='TaxDate']")));708 BatchChildRecord.setFieldValue('custrecord_ava_batchdocno', NS_RecordId);709 710 //save netsuite transaction data into custom record711 var NS_Record = null, NS_RecordType;712 if(DocType == 2)713 {714 try715 {716 var NS_Record = nlapiLoadRecord('invoice',NS_RecordId);717 NS_TranExist = 'T';718 DocType = 1;719 }720 catch(err)721 {722 try723 {724 var NS_Record = nlapiLoadRecord('cashsale',NS_RecordId);725 NS_TranExist = 'T';726 DocType = 3;727 }728 catch(err)729 {730 NS_TranExist = 'F';731 }732 }733 }734 else if(DocType == 6)735 {736 try737 {738 var NS_Record = nlapiLoadRecord('cashrefund',NS_RecordId);739 NS_TranExist = 'T';740 DocType = 4;741 }742 catch(err)743 {744 try745 {746 var NS_Record = nlapiLoadRecord('creditmemo',NS_RecordId);747 NS_TranExist = 'T';748 DocType = 5;749 }750 catch(err)751 {752 NS_TranExist = 'F';753 }754 }755 } 756 if(NS_TranExist == 'T')757 { 758 var Multiplier = (NS_Record.getFieldValue('type') == 'custinvc' || NS_Record.getFieldValue('type') == 'cashsale') ? 1 : -1; 759 NS_RecordType = (NS_Record.getFieldValue('type') == 'custinvc' || NS_Record.getFieldValue('type') == 'cashsale') ? 1 : 2;760 761 BatchChildRecord.setFieldValue('custrecord_ava_batchdoctype', DocType);762 BatchChildRecord.setFieldValue('custrecord_ava_netsuitedocno', NS_RecordId);763 BatchChildRecord.setFieldValue('custrecord_ava_netsuitedoctyp', NS_RecordType);764 BatchChildRecord.setFieldValue('custrecord_ava_netsuitedocdate', NS_Record.getFieldValue('trandate'));765 766 var MultiCurr = (NS_Record.getFieldValue('isbasecurrency') == 'F') ? 'T' : 'F';767 BatchChildRecord.setFieldValue('custrecord_ava_batchmulticurrency', MultiCurr); 768 if(MultiCurr == 'T')769 {770 MultiCurrBatch = 'T';771 }772 var subtotal = (NS_Record.getFieldValue('subtotal') == null) ? 0 : nlapiFormatCurrency(NS_Record.getFieldValue('subtotal'));773 var shipcost = (NS_Record.getFieldValue('shippingcost') == null) ? 0 : nlapiFormatCurrency(NS_Record.getFieldValue('shippingcost'));774 var handlingcost = (NS_Record.getFieldValue('handlingcost') == null) ? 0 : nlapiFormatCurrency(NS_Record.getFieldValue('handlingcost'));775 var giftcert = (NS_Record.getFieldValue('giftcertapplied') == null) ? 0 : nlapiFormatCurrency(NS_Record.getFieldValue('giftcertapplied'));776 var exchangeRate = NS_Record.getFieldValue('exchangerate');777 778 var TotalAmount = parseFloat(subtotal) + parseFloat(shipcost) + parseFloat(handlingcost) + parseFloat(giftcert);779 BatchChildRecord.setFieldValue('custrecord_ava_netsuitetotalamountfc', parseFloat(TotalAmount * Multiplier));780 781 TotalAmount = parseFloat(nlapiFormatCurrency(subtotal*exchangeRate)) + parseFloat(nlapiFormatCurrency(shipcost*exchangeRate)) + parseFloat(nlapiFormatCurrency(handlingcost*exchangeRate)) + parseFloat(nlapiFormatCurrency(giftcert*exchangeRate));782 BatchChildRecord.setFieldValue('custrecord_ava_netsuitetotalamount', nlapiFormatCurrency(TotalAmount * Multiplier));783 784 var Discount = nlapiFormatCurrency((NS_Record.getFieldValue('discountamount')== null) ? 0 : NS_Record.getFieldValue('discountamount'));785 BatchChildRecord.setFieldValue('custrecord_ava_netsuitetotaldiscount', Discount);786 787 var TaxTotal = (NS_Record.getFieldValue('taxtotal')== null) ? 0 : nlapiFormatCurrency(NS_Record.getFieldValue('taxtotal'));788 BatchChildRecord.setFieldValue('custrecord_ava_netsuitetotaltaxfc', parseFloat(TaxTotal * Multiplier));789 790 TaxTotal = parseFloat(nlapiFormatCurrency(TaxTotal * exchangeRate));791 BatchChildRecord.setFieldValue('custrecord_ava_netsuitetotaltax', nlapiFormatCurrency(TaxTotal * Multiplier)); 792 793 var filters = new Array(); 794 var columns = new Array();795 columns[0] = new nlobjSearchColumn('custrecord_ava_documentno');796 columns[1] = new nlobjSearchColumn('custrecord_ava_documenttype');797 columns[2] = new nlobjSearchColumn('custrecord_ava_documentdate');798 columns[3] = new nlobjSearchColumn('custrecord_ava_documentstatus');799 columns[4] = new nlobjSearchColumn('custrecord_ava_totalamount');800 columns[5] = new nlobjSearchColumn('custrecord_ava_totaldiscount');801 columns[6] = new nlobjSearchColumn('custrecord_ava_totalnontaxable');802 columns[7] = new nlobjSearchColumn('custrecord_ava_totaltaxable');803 columns[8] = new nlobjSearchColumn('custrecord_ava_totaltax');804 columns[9] = new nlobjSearchColumn('custrecord_ava_taxcalculationdate');805 columns[10] = new nlobjSearchColumn('custrecord_ava_documentid');806 columns[11] = new nlobjSearchColumn('custrecord_ava_multicurrency');807 columns[12] = new nlobjSearchColumn('custrecord_ava_exchangerate');808 809 // set filter to get related custom record810 filters[0] = new nlobjSearchFilter('custrecord_ava_documentinternalid', null, 'is', NS_RecordId);811 filters[1] = new nlobjSearchFilter('custrecord_ava_documentstatus', null, 'equalto', 3);812 813 var customRecord = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, columns);814 815 if(customRecord != null)816 {817 CR_RecordId = customRecord[0].getId();818 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxcrdoctype', customRecord[0].getValue('custrecord_ava_documenttype'));819 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxcrdocdate', customRecord[0].getValue('custrecord_ava_documentdate'));820 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxcrdocstatus', customRecord[0].getValue('custrecord_ava_documentstatus'));821 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxtotalamount', customRecord[0].getValue('custrecord_ava_totalamount'));822 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxtotaldiscount', customRecord[0].getValue('custrecord_ava_totaldiscount')); 823 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotalexemption', customRecord[0].getValue('custrecord_ava_totalnontaxable')); 824 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotaltaxable', customRecord[0].getValue('custrecord_ava_totaltaxable')); 825 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotaltax', customRecord[0].getValue('custrecord_ava_totaltax')); 826 BatchChildRecord.setFieldValue('custrecord_ava_batchmulticurrency', customRecord[0].getValue('custrecord_ava_multicurrency')); 827 if(customRecord[0].getValue('custrecord_ava_exchangerate') != null && customRecord[0].getValue('custrecord_ava_exchangerate').length > 0)828 {829 var TotalAmount = nlapiFormatCurrency(customRecord[0].getValue('custrecord_ava_totalamount')) / nlapiFormatCurrency(customRecord[0].getValue('custrecord_ava_exchangerate'));830 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxtotalamountfc', nlapiFormatCurrency(TotalAmount)); 831 var TotalTax = nlapiFormatCurrency(customRecord[0].getValue('custrecord_ava_totaltax')) / nlapiFormatCurrency(customRecord[0].getValue('custrecord_ava_exchangerate'));832 BatchChildRecord.setFieldValue('custrecord_ava_avacrtotaltaxfc', nlapiFormatCurrency(TotalTax)); 833 }834 BatchChildRecord.setFieldValue('custrecord_ava_avacrtaxdate', customRecord[0].getValue('custrecord_ava_taxcalculationdate')); 835 NS_CRExist = 'T';836 }837 }838 // else839 // {840 // filters[0] = new nlobjSearchFilter('custrecord_ava_documentid', null, 'is', nlapiSelectValue( GetTaxResult[i], "./*[name()='DocCode']"));841 // filters[1] = new nlobjSearchFilter('custrecord_ava_documentstatus', null, 'is', 3);842 // }843 844 845 //set status flag in AVARECONCILEBATCHRECORDS846 if(NS_TranExist == 'F')847 {848 if(NS_CRExist == 'F')849 {850 BatchChildRecord.setFieldValue('custrecord_ava_statusflag', 1);//Only AVATAX 851 only_AVA++;852 }853 else854 {855 BatchChildRecord.setFieldValue('custrecord_ava_statusflag', 5);//Exists only in AVATAX & CUSTOMRECORD856 AVA_CR++;857 }858 }859 else 860 {861 if(NS_CRExist == 'F')862 {863 BatchChildRecord.setFieldValue('custrecord_ava_statusflag', 4);//Exists only in AVATAX & NETSUITE864 AVA_NS++; 865 }866 else867 {868 //Fo Total Amount comparison869 var AVA_TotalAmount = nlapiFormatCurrency(BatchChildRecord.getFieldValue('custrecord_ava_avataxtotalamount'));870 var NS_TotalAmount = nlapiFormatCurrency(BatchChildRecord.getFieldValue('custrecord_ava_netsuitetotalamount'));871 var CR_TotalAmount = nlapiFormatCurrency(BatchChildRecord.getFieldValue('custrecord_ava_avacrtaxtotalamount'));872 873 //For Total Tax comparison874 var AVA_TotalTax = nlapiFormatCurrency(BatchChildRecord.getFieldValue('custrecord_ava_avatotaltax'));875 var NS_TotalTax = nlapiFormatCurrency(BatchChildRecord.getFieldValue('custrecord_ava_netsuitetotaltax'));876 var CR_TotalTax = nlapiFormatCurrency(BatchChildRecord.getFieldValue('custrecord_ava_avacrtotaltax'));877 878 if((AVA_TotalAmount == NS_TotalAmount) && (NS_TotalAmount == CR_TotalAmount) && (CR_TotalAmount == AVA_TotalAmount))879 {880 if((AVA_TotalTax == NS_TotalTax) && (NS_TotalTax == CR_TotalTax) && (CR_TotalTax == AVA_TotalTax))881 {882 BatchChildRecord.setFieldValue('custrecord_ava_statusflag', 8);//RECONCILED883 Reconciled++;884 }885 else886 {887 BatchChildRecord.setFieldValue('custrecord_ava_statusflag', 7);//Exists in AVATAX & NETSUITE & CUSTOMRECORD888 AVA_NS_CR++;889 }890 }891 else 892 {893 BatchChildRecord.setFieldValue('custrecord_ava_statusflag', 7);//Exists in AVATAX & NETSUITE & CUSTOMRECORD894 AVA_NS_CR++;895 }896 }897 } 898 899 var BatchRecId = nlapiSubmitRecord(BatchChildRecord, false);900 901 LastDocCode = NS_RecordId;902 903 var TempDocArray = NSIdsText;904 905 if(TempDocArray != null && TempDocArray.length > 3500)906 {907 if(NS_TranExist == 'T') 908 {909 NS_NextDocField = NS_CreatedDocField;910 NSIdsCurrText += NS_RecordId + ',';911 NS_NextDocField = (NS_NextDocField=='custrecord_ava_nscreateddocids1')? 'custrecord_ava_nscreateddocids2' : ((NS_NextDocField == 'custrecord_ava_nscreateddocids2') ? 'custrecord_ava_nscreateddocids3': 'custrecord_ava_nscreateddocids4');912 }913 }914 else915 {916 if(NS_TranExist == 'T') 917 {918 NSIdsText += NS_RecordId + ',';919 }920 }921 922 var TempDocArray = CRIdsText;923 if(TempDocArray != null && TempDocArray.length > 3500)924 { 925 if(NS_CRExist == 'T')926 {927 CR_NextDocField = CR_CreatedDocField;928 CRIdsCurrText += CR_RecordId + ',';929 CR_NextDocField = (CR_NextDocField=='custrecord_ava_createddocids1')? 'custrecord_ava_createddocids2' : ((CR_NextDocField == 'custrecord_ava_createddocids2') ? 'custrecord_ava_createddocids3': 'custrecord_ava_createddocids4');930931 }932 }933 else934 {935 if(NS_CRExist == 'T')936 {937 CRIdsText += CR_RecordId + ',';938 }939 }940 }941 }942 catch(err)943 {944 nlapiLogExecution('Error','Got Error on Record Submit for DocCode: ' + nlapiSelectValue( GetTaxResult[i], "./*[name()='DocCode']"), err);945 break;946 }947 }948 949 // Submit progress details into Batch 950 fields = new Array();951 values = new Array();952 953 if(NSIdsText != '')954 {955 fields[fields.length] = NS_CreatedDocField;956 values[values.length] = NSIdsText; 957 }958 959 if(NSIdsCurrText != '')960 {961 fields[fields.length] = NS_NextDocField;962 values[values.length] = NSIdsCurrText; 963 }964 965 if(CRIdsText != '')966 {967 fields[fields.length] = CR_CreatedDocField;968 values[values.length] = CRIdsText; 969 }970 971 if(CRIdsCurrText != '')972 {973 fields[fields.length] = CR_NextDocField;974 values[values.length] = CRIdsCurrText; 975 }976 977 fields[fields.length] = 'custrecord_ava_onlyava';978 values[values.length] = only_AVA;979 980 fields[fields.length] = 'custrecord_ava_avacr';981 values[values.length] = AVA_CR;982 983 fields[fields.length] = 'custrecord_ava_avans';984 values[values.length] = AVA_NS;985 986 fields[fields.length] = 'custrecord_ava_reconciled';987 values[values.length] = Reconciled;988 989 fields[fields.length] = 'custrecord_ava_avanscr';990 values[values.length] = AVA_NS_CR;991 992 fields[fields.length] = 'custrecord_ava_lastdoccode';993 values[values.length] = LastDocCode;994 995 if(MultiCurrBatch == 'T')996 {997 fields[fields.length] = 'custrecord_ava_multicurrencybatch';998 values[values.length] = 'T';999 }1000 1001 nlapiSubmitField('customrecord_avareconcilebatch', BatchId, fields, values); 1002 1003 }1004 else if(GetTaxResult == null || (GetTaxResult != null && GetTaxResult.length == 0))1005 {1006 AVA_ResultFlag = false;1007 } 1008 }1009 else1010 {1011 nlapiLogExecution('Debug', 'Please contact the administrator.', 'Result Code is not Success.'); 1012 }1013 }1014 else1015 {1016 nlapiLogExecution('Error', 'Please contact the administrator.', 'Reconciliation Tax History call was not successful.'); 1017 }1018 }1019 1020 //First phase is complete1021 if(AVA_ResultFlag == false)1022 { 1023 fields = new Array();1024 values = new Array();1025 1026 fields[fields.length] = 'custrecord_ava_batchphase';1027 values[values.length] = 0;1028 1029 fields[fields.length] = 'custrecord_ava_batchprogress';1030 values[values.length] = 60; 1031 1032 nlapiSubmitField('customrecord_avareconcilebatch', BatchId, fields, values);1033 }1034}103510361037function AVA_ReconcileTaxBody(DocStatus, LastDocCode)1038{1039 nlapiLogExecution('Debug', 'LastDocCode in AVA_ReconcileTaxBody', LastDocCode);1040 var soap = null;1041 soap = '\t<soap:Body>\n';1042 soap += '\t\t<ReconcileTaxHistory xmlns="http://avatax.avalara.com/services">\n';1043 soap += '\t\t\t<ReconcileTaxHistoryRequest>\n';1044 soap += '\t\t\t\t<CompanyCode><![CDATA[' + nlapiGetContext().getCompany() + ']]></CompanyCode>\n';1045// soap += '\t\t\t\t<CompanyCode><![CDATA[SOA]]></CompanyCode>\n';1046 if(LastDocCode != 0 && LastDocCode != null)1047 {1048 nlapiLogExecution('Debug', 'LastDocCode soap line added', '');1049 soap += '\t\t\t\t<LastDocCode><![CDATA['+ LastDocCode + ']]></LastDocCode>\n';1050 }1051 soap += '\t\t\t\t<Reconciled>0</Reconciled>\n';1052 soap += '\t\t\t\t<StartDate>'+ AVA_GetDate(StartDate,nlapiGetContext().getSetting('PREFERENCE', 'DATEFORMAT')) +'</StartDate>\n';1053 soap += '\t\t\t\t<EndDate>'+ AVA_GetDate(EndDate,nlapiGetContext().getSetting('PREFERENCE', 'DATEFORMAT')) +'</EndDate>\n';1054 soap += '\t\t\t\t<DocStatus><![CDATA['+ DocStatus +']]></DocStatus>\n';1055 soap += '\t\t\t</ReconcileTaxHistoryRequest>\n';1056 soap += '\t\t</ReconcileTaxHistory>\n';1057 soap += '\t</soap:Body>\n';1058 nlapiLogExecution('Debug', 'soap', soap);1059 return soap;1060}10611062function AVA_LoadBatchValues()1063{1064 var NSInternalIds = '', CRInternalIds = ''; 1065 1066 var BatchRecord = nlapiLoadRecord('customrecord_avareconcilebatch', BatchId);10671068 BatchName = BatchRecord.getFieldValue('custrecord_ava_batchname');1069 StartDate = BatchRecord.getFieldValue('custrecord_ava_batchstartdate');1070 EndDate = BatchRecord.getFieldValue('custrecord_ava_batchenddate');1071 only_AVA = BatchRecord.getFieldValue('custrecord_ava_onlyava');1072 AVA_CR = BatchRecord.getFieldValue('custrecord_ava_avacr');1073 AVA_NS = BatchRecord.getFieldValue('custrecord_ava_avans');1074 AVA_NS_CR = BatchRecord.getFieldValue('custrecord_ava_avanscr');1075 Reconciled = BatchRecord.getFieldValue('custrecord_ava_reconciled');1076 only_NS = BatchRecord.getFieldValue('custrecord_ava_onlyns');1077 NS_CR = BatchRecord.getFieldValue('custrecord_ava_nscr');1078 only_CR = BatchRecord.getFieldValue('custrecord_ava_onlycr');1079 LastDocCode = BatchRecord.getFieldValue('custrecord_ava_lastdoccode');10801081 //Get NetSuite Processed Ids1082 if(BatchRecord.getFieldValue('custrecord_ava_nscreateddocids1') != null && BatchRecord.getFieldValue('custrecord_ava_nscreateddocids1').length > 3500)1083 {1084 if(BatchRecord.getFieldValue('custrecord_ava_nscreateddocids2') != null && BatchRecord.getFieldValue('custrecord_ava_nscreateddocids2').length > 3500)1085 {1086 if(BatchRecord.getFieldValue('custrecord_ava_nscreateddocids3') != null && BatchRecord.getFieldValue('custrecord_ava_nscreateddocids3').length > 3500)1087 {1088 NSIdsText = BatchRecord.getFieldValue('custrecord_ava_nscreateddocids4');1089 NS_CreatedDocField = 'custrecord_ava_nscreateddocids4';1090 }1091 else1092 {1093 NSIdsText = BatchRecord.getFieldValue('custrecord_ava_nscreateddocids3');1094 NS_CreatedDocField = 'custrecord_ava_nscreateddocids3';1095 }1096 }1097 else1098 {1099 NSIdsText = BatchRecord.getFieldValue('custrecord_ava_nscreateddocids2');1100 NS_CreatedDocField = 'custrecord_ava_nscreateddocids2';1101 }1102 }1103 else1104 {1105 NSIdsText = BatchRecord.getFieldValue('custrecord_ava_nscreateddocids1');1106 NS_CreatedDocField = 'custrecord_ava_nscreateddocids1';1107 }1108 1109 NS_NextDocField = NS_CreatedDocField;1110 1111 1112 if(NSIdsText == null || NSIdsText == 0)1113 {1114 NSIdsText = '';1115 }1116 1117 //Get Custom Record Processed Ids(for time being storing values in avatax id fields)1118 if(BatchRecord.getFieldValue('custrecord_ava_createddocids1') != null && BatchRecord.getFieldValue('custrecord_ava_createddocids1').length > 3500)1119 {1120 if(BatchRecord.getFieldValue('custrecord_ava_createddocids2') != null && BatchRecord.getFieldValue('custrecord_ava_createddocids2').length > 3500)1121 {1122 if(BatchRecord.getFieldValue('custrecord_ava_createddocids3') != null && BatchRecord.getFieldValue('custrecord_ava_createddocids3').length > 3500)1123 {1124 CRIdsText = BatchRecord.getFieldValue('custrecord_ava_createddocids4');1125 CR_CreatedDocField = 'custrecord_ava_createddocids4';1126 }1127 else1128 {1129 CRIdsText = BatchRecord.getFieldValue('custrecord_ava_createddocids3');1130 CR_CreatedDocField = 'custrecord_ava_createddocids3';1131 }1132 }1133 else1134 {1135 CRIdsText = BatchRecord.getFieldValue('custrecord_ava_createddocids2');1136 CR_CreatedDocField = 'custrecord_ava_createddocids2';1137 }1138 }1139 else1140 {1141 CRIdsText = BatchRecord.getFieldValue('custrecord_ava_createddocids1');1142 CR_CreatedDocField = 'custrecord_ava_createddocids1';1143 }1144 1145 CR_NextDocField = CR_CreatedDocField;1146 1147 if(CRIdsText == null || CRIdsText == 0)1148 {1149 CRIdsText = '';1150 }1151 1152 if(BatchRecord.getFieldValue('custrecord_ava_batchphase') == '0' || BatchRecord.getFieldValue('custrecord_ava_batchphase') == '1')1153 { 1154 for(var i=1; i<=4 ; i++)1155 {1156 var NS_FieldIds = BatchRecord.getFieldValue('custrecord_ava_nscreateddocids'+i);1157 NSInternalIds += NS_FieldIds;1158 1159 var CR_FieldIds = BatchRecord.getFieldValue('custrecord_ava_createddocids'+i);1160 CRInternalIds += CR_FieldIds;1161 }1162 1163 NSIdsArray = AVA_SplitTextField(NSInternalIds);1164 CRIdsArray = AVA_SplitTextField(CRInternalIds); 1165 1166 if(BatchRecord.getFieldValue('custrecord_ava_batchphase') == '1')1167 {1168 NSIdsArray[NSIdsArray.length-1] = 0;//this was done so tht hte header custom records existing with null or blank value in 'NetSuite Document Internal ID' field can be fetched. Last element in the array is blank 1169 }1170 }117111721173}117411751176/////////////////////////////////////////////////////////////////////////////////////////////////1177/////////////////////////////////////////////////////////////////////////////////////////////////1178// End of First Suitelet1179/////////////////////////////////////////////////////////////////////////////////////////////////1180///////////////////////////////////////////////////////////////////////////////////////////////// 1181118211831184/////////////////////////////////////////////////////////////////////////////////////////////////1185/////////////////////////////////////////////////////////////////////////////////////////////////1186// Start of Second Suitelet1187/////////////////////////////////////////////////////////////////////////////////////////////////1188///////////////////////////////////////////////////////////////////////////////////////////////// 11891190//Scheduled Script for deletion of Custom records1191function AVA_DeleteReconciledCustomRecords()1192{1193 // Will be maintaining the deleted records counter in custrecord_ava_avacr field of batch as this field will be always 01194 // bcoz of DocId removal. 11951196 while(nlapiGetContext().getRemainingUsage() > MinUsage)1197 { 1198 nlapiLogExecution('Debug','Start Deletion','');1199 var filters = new Array();1200 filters[0] = new nlobjSearchFilter('custrecord_ava_batchstatus', null, 'equalto', 3);1201 1202 var columns = new Array();1203 columns[0] = new nlobjSearchColumn('custrecord_ava_totalrecords');1204 columns[1] = new nlobjSearchColumn('custrecord_ava_onlyava');1205 columns[2] = new nlobjSearchColumn('custrecord_ava_batchname');1206 1207 var searchResult = nlapiSearchRecord('customrecord_avareconcilebatch', null, filters, columns);12081209 if(searchResult != null && searchResult.length > 0)1210 {1211 for(var i=0; nlapiGetContext().getRemainingUsage() > MinUsage && i < searchResult.length ; i++)1212 {1213 nlapiSubmitField('customrecord_avareconcilebatch', searchResult[i].getId(), 'custrecord_ava_batchprogress', 1, false);1214 1215 while(nlapiGetContext().getRemainingUsage() > MinUsage)1216 { 1217 nlapiLogExecution('Debug','Batch records:',searchResult[i].getId());1218 var delCtr = 0, custfilters = new Array(); 1219 //custfilters[0] = new nlobjSearchFilter('custrecord_ava_batchid', null, 'anyof', searchResult[i].getId());1220 custfilters[0] = new nlobjSearchFilter('custrecord_ava_reconcilebatchname', null, 'is', searchResult[i].getValue('custrecord_ava_batchname'));1221 1222 try1223 {1224 var searchCust = nlapiSearchRecord('customrecord_avareconcilebatchrecords', null, custfilters, null);1225 }1226 catch(err)1227 {1228 nlapiLogExecution('Debug', 'Search not success: ', err);1229 nlapiLogExecution('Debug', 'Error Details: ', err.getDetails());1230 }1231 1232 if(searchCust != null)1233 {1234 try1235 {1236 var TotalRecs = parseInt(searchResult[i].getValue('custrecord_ava_totalrecords'));1237 1238 nlapiLogExecution('Debug','Batch records searchCust:',searchCust.length);1239 1240 for(var k=0; nlapiGetContext().getRemainingUsage() > MinUsage && k < searchCust.length ; k++)1241 { 1242 nlapiDeleteRecord('customrecord_avareconcilebatchrecords', searchCust[k].getId());1243 nlapiLogExecution('Debug','record deleted', searchCust[k].getId());1244 delCtr++;1245 }1246 1247 fields = new Array();1248 values = new Array();1249 1250 fields[fields.length] ='custrecord_ava_batchprogress';1251 values[fields.length] = Math.floor(((parseFloat(delCtr) + parseFloat((searchResult[i].getValue('custrecord_ava_avacr') != null && searchResult[i].getValue('custrecord_ava_avacr').length > 0 ? searchResult[i].getValue('custrecord_ava_avacr') : 0)))/ parseFloat(TotalRecs)) * 100);1252 1253 fields[fields.length] ='custrecord_ava_avacr';1254 values[fields.length] = parseFloat(searchResult[i].getValue('custrecord_ava_avacr')) + parseFloat(delCtr);1255 1256 nlapiSubmitField('customrecord_avareconcilebatch', searchResult[0].getId(), fields, values, false);1257 }1258 catch(err)1259 {1260 nlapiLogExecution('Debug', 'Deletion not successful: ', err);1261 nlapiLogExecution('Debug', 'Error Details: ', err.getDetails());1262 }1263 1264 }1265 else if(searchCust == null || searchCust.length == 0)1266 {1267 nlapiLogExecution('Debug','Batch records searchCust is null:','');1268 nlapiDeleteRecord('customrecord_avareconcilebatch', searchResult[i].getId());1269 break;1270 }1271 }1272 1273 if(nlapiGetContext().getRemainingUsage() <= MinUsage)1274 {1275 nlapiScheduleScript(nlapiGetContext.getScriptId(), nlapiGetContext.getDeploymentId());1276 }1277 } 1278 }1279 else1280 {1281 // no batches left for deletion1282 break;1283 }1284 }1285}128612871288function AVA_ReconciliationResults(request,response)1289{1290 if(AVA_CheckService('TaxSvc') == 0 && AVA_CheckSecurity( 8 ) == 0)1291 {1292 if(request.getMethod() == 'GET')1293 {1294 var AVA_TransactionForm = nlapiCreateForm('Reconciliation Batches');1295 AVA_TransactionForm.setTitle('Reconciliation Batches');1296 AVA_TransactionForm.setScript('customscript_avadeletebatch_client');1297 1298 var AVA_TransactionList = AVA_TransactionForm.addSubList('custpage_avabatchlist', 'list','Select Batches');1299 AVA_TransactionList.addField('ava_batchid','text', 'Batch ID').setDisplayType('hidden');1300 AVA_TransactionList.addField('apply','checkbox', 'Delete');1301 AVA_TransactionList.addField('ava_batchname','text', 'Name');1302 AVA_TransactionList.addField('ava_batchdate','date', 'Batch Date');1303 AVA_TransactionList.addField('ava_startdate','date', 'Start Date');1304 AVA_TransactionList.addField('ava_enddate','date', 'End Date');1305 AVA_TransactionList.addField('ava_batchprogress','text', 'Batch Progress');1306 AVA_TransactionList.addField('ava_batchstatus','text', 'Batch Status');1307 AVA_TransactionList.addField('ava_viewdetails','text', 'Details');1308 1309 var cols = new Array();1310 cols[0] = new nlobjSearchColumn('custrecord_ava_batchname');1311 cols[1] = new nlobjSearchColumn('custrecord_ava_batchdate');1312 cols[2] = new nlobjSearchColumn('custrecord_ava_batchstartdate');1313 cols[3] = new nlobjSearchColumn('custrecord_ava_batchenddate');1314 cols[4] = new nlobjSearchColumn('custrecord_ava_batchstatus');1315 cols[5] = new nlobjSearchColumn('custrecord_ava_batchprogress');1316 cols[6] = new nlobjSearchColumn('custrecord_ava_batchphase');1317 1318 var searchresult = nlapiSearchRecord('customrecord_avareconcilebatch', null, null, cols);1319 1320 for(var i = 0; searchresult != null && i < searchresult.length; i++)1321 {1322 AVA_TransactionList.setLineItemValue('ava_batchid', i+1, searchresult[i].getId());1323 AVA_TransactionList.setLineItemValue('ava_batchname', i+1, searchresult[i].getValue('custrecord_ava_batchname'));1324 AVA_TransactionList.setLineItemValue('ava_batchdate', i+1, searchresult[i].getValue('custrecord_ava_batchdate'));1325 AVA_TransactionList.setLineItemValue('ava_startdate', i+1, searchresult[i].getValue('custrecord_ava_batchstartdate'));1326 AVA_TransactionList.setLineItemValue('ava_enddate', i+1, searchresult[i].getValue('custrecord_ava_batchenddate'));1327 var BatchStatus = searchresult[i].getValue('custrecord_ava_batchstatus');1328 1329 if(BatchStatus == 3)1330 {1331 var BatchPhase = searchresult[i].getValue('custrecord_ava_batchphase');1332 BatchStatus = (BatchPhase == 0) ? 'In Queue for Deletion' : ((BatchPhase == 1) ? 'In Progress...Deleting Records' : 'Error');1333 }1334 else1335 {1336 BatchStatus = (BatchStatus == 0) ? 'In Queue' : ((BatchStatus == 1) ? 'In Progress' : ((BatchStatus == 2) ? 'Completed' : 'Error'));1337 }1338 1339 AVA_TransactionList.setLineItemValue('ava_batchstatus', i+1, BatchStatus);1340 AVA_TransactionList.setLineItemValue('ava_batchprogress', i+1, searchresult[i].getValue('custrecord_ava_batchprogress'));1341 1342 if(searchresult[i].getValue('custrecord_ava_batchstatus') == 2)1343 {1344 var URL1 = nlapiResolveURL('SUITELET', 'customscript_ava_reconcilelist_suitelet', 'customdeploy_ava_reconcilelist', false);1345 URL1 = URL1 + '&ava_batchid=' + searchresult[i].getId() + '&ava_status=2&ava_liststart=0&ava_oldstatus=8&ava_linecount=0';1346 var FinalURL = '<a href="' + URL1 + '" target="_blank">View Details</a>';1347 1348 AVA_TransactionList.setLineItemValue('ava_viewdetails', i+1, FinalURL);1349 }1350 }1351 1352 AVA_TransactionForm.addSubmitButton('Submit');1353 AVA_TransactionForm.addButton('ava_refresh','Refresh', "window.location = '" + nlapiResolveURL('SUITELET', 'customscript_ava_reconciliation_suitelet', 'customdeploy_ava_reconcileresult') + "&compid=" + nlapiGetContext().getCompany() + "&whence='");1354 //AVA_TransactionForm.addPageLink('breadcrumb', 'View Reconciliation Results', nlapiResolveURL('SUITELET', 'customscript_ava_reconciliation_suitelet', 'customdeploy_ava_reconcileresult'));1355 AVA_TransactionForm.addPageLink('crosslink', 'Create Reconciliation Batch', nlapiResolveURL('SUITELET', 'customscript_avareconcilelist_suitelet', 'customdeploy_avareconcilelist'));1356 1357 response.writePage(AVA_TransactionForm);1358 }1359 else1360 {1361 //set batch status field value to 3 for deletion1362 1363 var LineCount = request.getLineItemCount('custpage_avabatchlist');1364 1365 for ( var i = 1; i <= LineCount ; i++ )1366 {1367 if ( request.getLineItemValue('custpage_avabatchlist','apply', i) == 'T')1368 {1369 var BatchId = request.getLineItemValue('custpage_avabatchlist','ava_batchid', i);1370 1371 var fields = new Array();1372 var values = new Array();1373 1374 fields[0] = 'custrecord_ava_batchstatus';1375 values[0] = 3;1376 1377 fields[1] ='custrecord_ava_batchprogress';1378 values[1] = 0;1379 1380 fields[2] ='custrecord_ava_batchphase';1381 values[2] = 0;1382 1383 fields[3] = 'custrecord_ava_onlyava';1384 values[3] = 0;1385 1386 nlapiSubmitField('customrecord_avareconcilebatch', BatchId, fields, values, false);1387 }1388 } 1389 nlapiScheduleScript('customscript_avadeletebatch_sched','customdeploy_avadeletebatch_deploy1'); 1390 nlapiSetRedirectURL('TASKLINK', 'CARD_-29');1391 }1392 }1393}13941395function AVA_SaveRecord()1396{1397 var alertFlag = 'F', alertMsg = '';1398 1399 for ( var i = 1; i <= nlapiGetLineItemCount('custpage_avabatchlist'); i++ )1400 {1401 if( nlapiGetLineItemValue('custpage_avabatchlist','apply', i) == 'T' )1402 {1403 var BatchStatus = nlapiGetLineItemValue('custpage_avabatchlist','ava_batchstatus', i);1404 switch(BatchStatus)1405 {1406 case 'In Queue': 1407 BatchStatus = 0;1408 break;1409 1410 case 'In Progress': 1411 BatchStatus = 1;1412 break; 1413 1414 case 'Completed': 1415 BatchStatus = 2;1416 break;1417 1418 case 'Delete': 1419 BatchStatus = 3;1420 break; 1421 1422 case 'default': 1423 BatchStatus = 4;1424 break; 1425 }1426 1427 if(BatchStatus == 1)1428 {1429 var BatchName = nlapiGetLineItemValue('custpage_avabatchlist','ava_batchname', i);1430 alertFlag = 'T';1431 alertMsg += BatchName + '\n';1432 }1433 }1434 }1435 1436 if(alertFlag == 'T')1437 {1438 alert('Following Batches are in Progress and cannot be deleted: \n' + alertMsg);1439 return false;1440 }1441 1442 return true;1443}14441445function AVA_ReconciliationList(request,response)1446{1447 if(AVA_CheckService('TaxSvc') == 0 && AVA_CheckSecurity( 7 ) == 0)1448 {1449 if(request.getMethod() == 'GET' || request.getMethod() == 'POST')1450 {1451 var BatchId = request.getParameter('ava_batchid');1452 var BatchStatus = request.getParameter('ava_status');1453 var AVA_Message = 'Batch Name or Batch Status Missing';1454 1455 BatchName = nlapiLookupField('customrecord_avareconcilebatch', BatchId, 'custrecord_ava_batchname');1456 1457 if(BatchId == null || BatchId == '' || BatchStatus == null || BatchStatus == '') 1458 {1459 var AVA_Notice = AVA_NoticePage(AVA_Message);1460 response.write(AVA_Notice);1461 }1462 else1463 {1464 var AVA_TransactionForm = nlapiCreateForm('Reconciliation Results');1465 AVA_TransactionForm.setTitle('Reconciliation Results');1466 AVA_TransactionForm.setScript('customscript_ava_reconcileresult_client');1467 1468 AVA_TransactionForm.addField('ava_batchid', 'text', 'Batch ID').setDisplayType('hidden');1469 AVA_TransactionForm.getField('ava_batchid').setDefaultValue(BatchId);1470 1471 AVA_TransactionForm.addField('ava_batchname', 'text', 'Batch Name').setDisplayType('inline');1472 AVA_TransactionForm.getField('ava_batchname').setDefaultValue(BatchName);1473 1474 AVA_TransactionForm.addField('ava_batchdaterange','text','Batch Date Range').setDisplayType('inline');1475 AVA_TransactionForm.addField('ava_total','integer','Total Records').setDisplayType('inline'); 1476 AVA_TransactionForm.addField('ava_onlyava','integer','Only AvaTax').setDisplayType('inline');1477 AVA_TransactionForm.addField('ava_onlyns','integer','Only NetSuite').setDisplayType('inline');1478 AVA_TransactionForm.addField('ava_onlycr','integer','Only Custom Record').setDisplayType('inline');1479 AVA_TransactionForm.addField('ava_avans','integer','AvaTax & NetSuite').setDisplayType('inline');1480 AVA_TransactionForm.addField('ava_nscr','integer','NetSuite & Custom Record').setDisplayType('inline');1481 AVA_TransactionForm.addField('ava_avacr','integer','AvaTax & Custom Record').setDisplayType('inline');1482 AVA_TransactionForm.addField('ava_avanscr','integer','AvaTax, NetSuite & Custom Record').setDisplayType('inline');1483 AVA_TransactionForm.addField('ava_reconciled','integer','Reconciled Count').setDisplayType('inline');1484 AVA_TransactionForm.addField('ava_liststart','integer','List Start').setDisplayType('hidden');1485 1486 var SelectCriteria = AVA_TransactionForm.addField('ava_status','select','Sublist Criteria');1487 SelectCriteria.addSelectOption('1','Only AvaTax');1488 SelectCriteria.addSelectOption('2','Only NetSuite');1489 SelectCriteria.addSelectOption('3','Only Custom Record');1490 SelectCriteria.addSelectOption('4','AvaTax & NetSuite');1491 SelectCriteria.addSelectOption('5','AvaTax & Custom Record');1492 SelectCriteria.addSelectOption('6','NetSuite & Custom Record');1493 SelectCriteria.addSelectOption('7','AvaTax, NetSuite & Custom Record');1494 SelectCriteria.addSelectOption('8','Reconciled');1495 SelectCriteria.setDefaultValue(BatchStatus);14961497 AVA_RecordCountFilter(AVA_TransactionForm, BatchId);14981499 AVA_GetReconcileRecords(BatchId, BatchStatus);15001501 var AVA_Tab = AVA_TransactionForm.addTab('custpage_avatab', '');1502 1503 var AVA_TransactionList = AVA_TransactionForm.addSubList('results','list','Results',AVA_Tab);1504 AVA_TransactionList.addField('ava_date','text', 'Document Date');1505 AVA_TransactionList.addField('ava_tran','text', 'Document Code'); 1506 if(MultiCurr == 'T')1507 { 1508 AVA_TransactionList.addField('ava_multicurr','text', 'Multi-Currency');1509 }1510 1511 AVA_TransactionList.addField('ava_doctype','text', 'Document Type');1512 AVA_TransactionList.addField('ava_avaamount','text', 'AvaTax Service Total Amount');1513 AVA_TransactionList.addField('ava_avatax','text', 'AvaTax Service Total Tax');1514 AVA_TransactionList.addField('ava_nsamount','text', 'NetSuite Total Amount');1515 if(MultiCurr == 'T')1516 {1517 AVA_TransactionList.addField('ava_nsamountfc','text', 'NetSuite Total Amount (Foreign Currency)');1518 }1519 1520 AVA_TransactionList.addField('ava_nstax','text', 'NetSuite Total Tax');1521 if(MultiCurr == 'T')1522 {1523 AVA_TransactionList.addField('ava_nstaxfc','text', 'NetSuite Total Tax (Foreign Currency)');1524 }1525 AVA_TransactionList.addField('ava_cramount','text', 'AvaTax Custom Record Total Amount');1526 if(MultiCurr == 'T')1527 {1528 AVA_TransactionList.addField('ava_cramountfc','text', 'AvaTax Custom Record Total Amount (Foreign Currency)');1529 }1530 AVA_TransactionList.addField('ava_crtax','text', 'AvaTax Custom Record Total Tax');1531 if(MultiCurr == 'T')1532 {1533 AVA_TransactionList.addField('ava_crtaxfc','text', 'AvaTax Custom Record Total Tax (Foreign Currency)');1534 }1535 1536 AVA_TransactionForm.addField('ava_oldstatus','integer','Old Status').setDisplayType('hidden');1537 AVA_TransactionForm.getField('ava_oldstatus').setDefaultValue(request.getParameter('ava_oldstatus'));1538 1539 var ListStart = AVA_SetSublistValues(AVA_TransactionList, BatchId, parseFloat(BatchStatus));1540 AVA_TransactionForm.getField('ava_liststart').setDefaultValue(ListStart);1541 1542 AVA_TransactionForm.addField('ava_linecount','integer','Line Count').setDisplayType('hidden');1543 AVA_TransactionForm.getField('ava_linecount').setDefaultValue(AVA_LineCount);15441545 var FirstLink = '<<First Page';1546 var PrevLink = 'Previous';1547 var NextLink = 'Next';1548 var LastLink = 'Last Page>>';1549 1550 //First Page1551 if(AVA_PrevFlag == 'T')1552 {1553 var URL1 = nlapiResolveURL('SUITELET', 'customscript_ava_reconcilelist_suitelet', 'customdeploy_ava_reconcilelist', false);1554 URL1 = URL1 + '&ava_batchid=' + request.getParameter('ava_batchid') + '&ava_status=' + request.getParameter('ava_status'); 1555 URL1 += '&ava_liststart=0&ava_oldstatus=' + BatchStatus;1556 1557 var FinalURL;1558 //FinalURL = ' <a href="'+ URL1 +'"><<First Page</a>';//>1559 FirstLink = '<b><a href="'+ URL1 +'">\t\t\t\t<<First Page</a></b>';//>1560 } 1561 1562 //Previous1563 if(AVA_PrevFlag == 'T')1564 {1565 var URL1 = nlapiResolveURL('SUITELET', 'customscript_ava_reconcilelist_suitelet', 'customdeploy_ava_reconcilelist', false);1566 URL1 = URL1 + '&ava_batchid=' + request.getParameter('ava_batchid') + '&ava_status=' + request.getParameter('ava_status'); 1567 URL1 += '&ava_liststart='+ ListStart +'&ava_oldstatus=' + BatchStatus + '&ava_linecount=' + AVA_LineCount + '&ava_flag=F';1568 1569 PrevLink = '<b> <a href="'+ URL1 +'">Previous</a></b>';1570 }1571 1572 //Next1573 if(AVA_NextFlag == 'T')1574 {1575 URL1 = nlapiResolveURL('SUITELET', 'customscript_ava_reconcilelist_suitelet', 'customdeploy_ava_reconcilelist', false);1576 URL1 = URL1 + '&ava_batchid=' + request.getParameter('ava_batchid') + '&ava_status=' + request.getParameter('ava_status') + '&ava_liststart=' + ListStart + '&ava_oldstatus=' + BatchStatus + '&ava_linecount=' + AVA_LineCount + '&ava_flag=T';1577 1578 NextLink = '<b> <a href="'+ URL1 +'">Next</a></b>';1579 }1580 1581 //Last Page1582 if(AVA_NextFlag == 'T')1583 {1584 URL1 = nlapiResolveURL('SUITELET', 'customscript_ava_reconcilelist_suitelet', 'customdeploy_ava_reconcilelist', false);1585 URL1 = URL1 + '&ava_batchid=' + request.getParameter('ava_batchid') + '&ava_status=' + request.getParameter('ava_status') + '&ava_liststart=' + AVA_EndPage + '&ava_oldstatus=' + BatchStatus + '&ava_linecount=' + AVA_LineCount;1586 1587 LastLink = '<b> <a href="'+ URL1 +'">Last Page>></a></b>';1588 }1589 1590 var emptyCells = '<td></td><td></td><td></td><td></td><td></td><td></td><td></td>';1591 var html = '<table cellspacing="20" align="center"><tr>' + emptyCells + emptyCells +'<td><font size="1">' + FirstLink+ '</font></td><td><font size="1">| ' + PrevLink + '</font></td>';1592 html +='<td><font size="1">| ' + NextLink + ' |</font></td><td><font size="1">' + LastLink+ '</font></td></tr></table>';1593 var PagingHtml = AVA_TransactionForm.addField('ava_pagelinks', 'help', html, null, AVA_Tab);1594 PagingHtml.setLayoutType('outsidebelow','startrow');1595 1596 if(MultiCurr == 'T')1597 {1598 AVA_TransactionForm.addField('ava_star','help','(*) indicates Multi-Currency Transactions', null, AVA_Tab).setLayoutType('outsidebelow','startrow');1599 }16001601// AVA_TransactionForm.addSubmitButton('Refresh');1602 response.writePage(AVA_TransactionForm); 1603 }1604 }1605 }1606 1607}16081609function AVA_RecordCountFilter(AVA_TransactionForm, BatchId)1610{1611 var BatchRec = nlapiLoadRecord('customrecord_avareconcilebatch',BatchId);1612 1613 if(BatchRec != null)1614 {1615 var DateRange = BatchRec.getFieldValue('custrecord_ava_batchstartdate') + ' - ' + BatchRec.getFieldValue('custrecord_ava_batchenddate');1616 AVA_TransactionForm.getField('ava_batchdaterange').setDefaultValue(DateRange);1617 1618 only_AVA = BatchRec.getFieldValue('custrecord_ava_onlyava');1619 AVA_TransactionForm.getField('ava_onlyava').setDefaultValue(only_AVA);1620 1621 only_NS = BatchRec.getFieldValue('custrecord_ava_onlyns');1622 AVA_TransactionForm.getField('ava_onlyns').setDefaultValue(only_NS);1623 1624 only_CR = BatchRec.getFieldValue('custrecord_ava_onlycr');1625 AVA_TransactionForm.getField('ava_onlycr').setDefaultValue(only_CR);1626 1627 AVA_NS = BatchRec.getFieldValue('custrecord_ava_avans');1628 AVA_TransactionForm.getField('ava_avans').setDefaultValue(AVA_NS);1629 1630 NS_CR = BatchRec.getFieldValue('custrecord_ava_nscr');1631 AVA_TransactionForm.getField('ava_nscr').setDefaultValue(NS_CR); 1632 1633 AVA_CR = BatchRec.getFieldValue('custrecord_ava_avacr'); 1634 AVA_TransactionForm.getField('ava_avacr').setDefaultValue(AVA_CR);1635 1636 AVA_NS_CR = BatchRec.getFieldValue('custrecord_ava_avanscr'); 1637 AVA_TransactionForm.getField('ava_avanscr').setDefaultValue(AVA_NS_CR);1638 1639 Reconciled = BatchRec.getFieldValue('custrecord_ava_reconciled'); 1640 AVA_TransactionForm.getField('ava_reconciled').setDefaultValue(Reconciled);1641 1642 Total = BatchRec.getFieldValue('custrecord_ava_totalrecords');1643 AVA_TransactionForm.getField('ava_total').setDefaultValue(Total);1644 1645 MultiCurr = BatchRec.getFieldValue('custrecord_ava_multicurrencybatch');1646 }1647 1648}164916501651function AVA_SetSublistValues(AVA_TransactionList, BatchId, Criteria)1652{1653 nlapiLogExecution('Debug', 'Record Obj Array',recordObjArray.length);1654 var RecordCountStart, RecordCountText;1655 if(request.getMethod() == 'POST')1656 {1657 var j = m = 0;1658 AVA_LineCount = 0;1659 }1660 else1661 {1662 var j = m = (request.getParameter('ava_oldstatus') == request.getParameter('ava_status'))? parseFloat(request.getParameter('ava_liststart')):0;1663 AVA_LineCount = (request.getParameter('ava_oldstatus') == request.getParameter('ava_status'))? request.getParameter('ava_linecount'):0;1664 }1665 var ListLimit = nlapiGetContext().getSetting('PREFERENCE', 'LISTSEGMENTSIZE');1666 var MaxLength = parseFloat(m) + parseFloat(ListLimit); 1667 1668 var AVA_Flag = request.getParameter('ava_flag');1669 1670 if(AVA_Flag == 'F')1671 {1672 if(request.getParameter('ava_linecount')>0)1673 {1674 if(request.getParameter('ava_linecount')<ListLimit)1675 {1676 MaxLength = parseFloat(ListLimit) + parseFloat(AVA_LineCount);1677 ListStart = j = parseFloat(j) - parseFloat(MaxLength);1678 }1679 else1680 {1681 MaxLength = (parseFloat(ListLimit) * parseFloat(2));1682 ListStart = j = parseFloat(j) - parseFloat(MaxLength);1683 }1684 }1685 m = 0; 1686 MaxLength = ListLimit;1687 }1688 1689 for(var i=0 ; m < MaxLength && j<recordObjArray.length && j>=0; j++)1690 {1691 1692 AVA_TransactionList.setLineItemValue('ava_date',i+1,AVA_GetDocDate(Criteria,j));1693 var doctype = recordObjArray[j].getValue('custrecord_ava_batchdoctype');1694 1695 doctype = (doctype ==2)? 'SalesInvoice': ((doctype ==6)? 'ReturnInvoice': ((doctype ==1)? 'Invoice':((doctype ==3)? 'Cash Sale':((doctype ==4)? 'Cash Refund':'Credit Memo'))));1696 AVA_TransactionList.setLineItemValue('ava_doctype',i+1,doctype);1697 1698 if(Criteria != 1 && Criteria != 3 && Criteria != 5)1699 {1700 doctype = (doctype=='Cash Sale')? 'cashsale':((doctype=='Credit Memo')? 'creditmemo' : ((doctype=='Cash Refund')?'cashrefund': 'invoice'));1701 var URL1 = nlapiResolveURL('RECORD',doctype,recordObjArray[j].getValue('custrecord_ava_batchdocno'));1702 1703 var FinalURL = '<a href="' + URL1 + '" target="_blank">' + recordObjArray[j].getValue('custrecord_ava_batchdocno') + '</a>';1704 1705 AVA_TransactionList.setLineItemValue('ava_tran',i+1,FinalURL);1706 }1707 else1708 {1709 AVA_TransactionList.setLineItemValue('ava_tran',i+1,recordObjArray[j].getValue('custrecord_ava_batchdocno'));1710 }1711 1712 AVA_TransactionList.setLineItemValue('ava_avaamount',i+1,nlapiFormatCurrency(recordObjArray[j].getValue('custrecord_ava_avataxtotalamount')));1713 AVA_TransactionList.setLineItemValue('ava_avatax',i+1,nlapiFormatCurrency(recordObjArray[j].getValue('custrecord_ava_avatotaltax')));1714 AVA_TransactionList.setLineItemValue('ava_nsamount',i+1,nlapiFormatCurrency(recordObjArray[j].getValue('custrecord_ava_netsuitetotalamount')));1715 AVA_TransactionList.setLineItemValue('ava_nstax',i+1,nlapiFormatCurrency(recordObjArray[j].getValue('custrecord_ava_netsuitetotaltax')));1716 AVA_TransactionList.setLineItemValue('ava_cramount',i+1,nlapiFormatCurrency(recordObjArray[j].getValue('custrecord_ava_avacrtaxtotalamount')));1717 AVA_TransactionList.setLineItemValue('ava_crtax',i+1,nlapiFormatCurrency(recordObjArray[j].getValue('custrecord_ava_avacrtotaltax')));1718 1719 if(recordObjArray[j].getValue('custrecord_ava_batchmulticurrency') == 'T')1720 {1721 AVA_TransactionList.setLineItemValue('ava_multicurr',i+1,'*');1722 AVA_TransactionList.setLineItemValue('ava_nsamountfc',i+1,nlapiFormatCurrency(recordObjArray[j].getValue('custrecord_ava_netsuitetotalamountfc')));1723 AVA_TransactionList.setLineItemValue('ava_nstaxfc',i+1,nlapiFormatCurrency(recordObjArray[j].getValue('custrecord_ava_netsuitetotaltaxfc')));1724 AVA_TransactionList.setLineItemValue('ava_cramountfc',i+1,nlapiFormatCurrency(recordObjArray[j].getValue('custrecord_ava_avacrtaxtotalamountfc')));1725 AVA_TransactionList.setLineItemValue('ava_crtaxfc',i+1,nlapiFormatCurrency(recordObjArray[j].getValue('custrecord_ava_avacrtotaltaxfc')));1726 }1727 m++; 1728 i++;1729 }1730 1731 AVA_LineCount = i;1732 1733 if(AVA_Flag == 'F')1734 {1735 RecordCountStart = ListStart;1736 var RecordEnd = parseFloat(i) + parseFloat(ListStart);1737 RecordCountText = 'Records: ' + ((i==0) ? 1 : (parseFloat((RecordCountStart>=0)? RecordCountStart:0) + parseFloat(1))) + ' - ' + RecordEnd;1738 }1739 else1740 {1741 if(request.getMethod() == 'POST')1742 {1743 RecordCountStart = 0;1744 }1745 else1746 {1747 RecordCountStart = (request.getParameter('ava_oldstatus') == request.getParameter('ava_status'))? parseFloat(request.getParameter('ava_liststart')):0;1748 }1749 RecordCountText = 'Records: ' + ((i==0) ? 0 : (parseFloat(RecordCountStart) + parseFloat(1))) + ' - ' + m;1750 }1751 1752 if(RecordCountStart>0)1753 {1754 AVA_PrevFlag = 'T'; 1755 }1756 1757 if(m<recordObjArray.length)1758 {1759 AVA_NextFlag = 'T';1760 }1761 1762 try1763 {1764 AVA_EndPage = String(parseFloat(recordObjArray.length)/parseFloat(ListLimit));1765 var AmountSplit = new Array();1766 AmountSplit = AVA_EndPage.split('.');1767 AVA_EndPage = parseFloat(AmountSplit[0]) * parseFloat(ListLimit); 1768 1769 if(recordObjArray != null && (recordObjArray.length == AVA_EndPage))1770 {1771 AVA_EndPage = parseFloat(AVA_EndPage) - parseFloat(ListLimit);1772 }1773 }1774 catch(err)1775 {1776 }1777 1778 AVA_TransactionList.setHelpText(RecordCountText);1779 1780 return j; 1781}178217831784function AVA_GetDocDate(Criteria,Ctr)1785{1786 var AVA_Date = null;1787 switch(Criteria)1788 {1789 case 1: AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_avataxdocdate');1790 break;1791 1792 case 2: AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_netsuitedocdate');1793 break; 1794 1795 case 3: AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_avacrtaxcrdocdate');1796 break; 1797 1798 case 4: if(recordObjArray[Ctr].getValue('custrecord_ava_avataxdocdate') !=null)1799 { 1800 AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_avataxdocdate');1801 }1802 else if(recordObjArray[Ctr].getValue('custrecord_ava_netsuitedocdate') !=null)1803 { 1804 AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_netsuitedocdate');1805 }1806 break;1807 1808 case 5: if(recordObjArray[Ctr].getValue('custrecord_ava_avataxdocdate') !=null)1809 { 1810 AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_avataxdocdate');1811 }1812 else if(recordObjArray[Ctr].getValue('custrecord_ava_avacrtaxcrdocdate') !=null)1813 { 1814 AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_avacrtaxcrdocdate');1815 }1816 break; 1817 1818 case 6: if(recordObjArray[Ctr].getValue('custrecord_ava_netsuitedocdate') !=null)1819 { 1820 AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_netsuitedocdate');1821 }1822 else if(recordObjArray[Ctr].getValue('custrecord_ava_avacrtaxcrdocdate') !=null)1823 { 1824 AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_avacrtaxcrdocdate');1825 }1826 break;1827 1828 default: if(recordObjArray[Ctr].getValue('custrecord_ava_avataxdocdate') !=null)1829 { 1830 AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_avataxdocdate');1831 }1832 else if(recordObjArray[Ctr].getValue('custrecord_ava_netsuitedocdate') !=null)1833 { 1834 AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_netsuitedocdate');1835 }1836 else if(recordObjArray[Ctr].getValue('custrecord_ava_avacrtaxcrdocdate') !=null)1837 { 1838 AVA_Date = recordObjArray[Ctr].getValue('custrecord_ava_avacrtaxcrdocdate');1839 }1840 }18411842 return AVA_Date;1843}184418451846function AVA_GetReconcileRecords(BatchId, Criteria)1847{1848 var BatchName = nlapiLookupField('customrecord_avareconcilebatch', BatchId, 'custrecord_ava_batchname');1849 1850 nlapiLogExecution('Debug','Criteria: ',Criteria);1851 recordIdArray = new Array();1852 recordObjArray= new Array();1853 1854 var filters = new Array();1855 filters[0] = new nlobjSearchFilter('custrecord_ava_reconcilebatchname', null, 'is', BatchName);1856 filters[1] = new nlobjSearchFilter('custrecord_ava_statusflag', null, 'equalto', Criteria);1857 1858 var cols = new Array();1859 cols[0] = new nlobjSearchColumn('custrecord_ava_batchdocno');1860 cols[1] = new nlobjSearchColumn('custrecord_ava_avataxtotalamount');1861 cols[2] = new nlobjSearchColumn('custrecord_ava_avatotaltax');1862 cols[3] = new nlobjSearchColumn('custrecord_ava_netsuitetotalamount');1863 cols[4] = new nlobjSearchColumn('custrecord_ava_netsuitetotaltax');1864 cols[5] = new nlobjSearchColumn('custrecord_ava_avacrtaxtotalamount');1865 cols[6] = new nlobjSearchColumn('custrecord_ava_avacrtotaltax');1866 cols[7] = new nlobjSearchColumn('custrecord_ava_statusflag');1867 cols[8] = new nlobjSearchColumn('custrecord_ava_avataxdocdate');1868 cols[9] = new nlobjSearchColumn('custrecord_ava_netsuitedocdate');1869 cols[10] = new nlobjSearchColumn('custrecord_ava_avacrtaxcrdocdate');1870 cols[11] = new nlobjSearchColumn('custrecord_ava_batchdoctype');1871 cols[12] = new nlobjSearchColumn('custrecord_ava_batchmulticurrency');1872 cols[13] = new nlobjSearchColumn('custrecord_ava_netsuitetotalamountfc');1873 cols[14] = new nlobjSearchColumn('custrecord_ava_netsuitetotaltaxfc');1874 cols[15] = new nlobjSearchColumn('custrecord_ava_avacrtaxtotalamountfc');1875 cols[16] = new nlobjSearchColumn('custrecord_ava_avacrtotaltaxfc');1876 1877 var searchResult = nlapiSearchRecord('customrecord_avareconcilebatchrecords', null, filters, cols);1878 1879 while(searchResult != null && searchResult.length > 0)1880 {1881 nlapiLogExecution('Debug','searchResult Length: ',searchResult.length);1882 for(var k=0; searchResult != null && k<searchResult.length; k++)1883 {1884 try1885 {1886 recordIdArray[recordIdArray.length] = searchResult[k].getId();1887 recordObjArray[recordObjArray.length] = searchResult[k];1888 }1889 catch(err)1890 {1891 1892 }1893 }1894 1895 if(searchResult.length >= 1000)1896 { 1897 filters[2] = new nlobjSearchFilter('internalid', null, 'noneof', recordIdArray);1898 1899 searchResult = nlapiSearchRecord('customrecord_avareconcilebatchrecords', null, filters, cols);1900 }1901 else1902 {1903 break;1904 }1905 }1906}190719081909// Field change function to track change to the sublist criteria and diaplay data accordingly1910function AVA_FieldChange(type, name)1911{1912 if(name == 'ava_status')1913 {1914 setWindowChanged(window, false);1915 var URL1 = nlapiResolveURL('SUITELET', 'customscript_ava_reconcilelist_suitelet', 'customdeploy_ava_reconcilelist', false);1916 URL1 = URL1 + '&ava_batchid=' + nlapiGetFieldValue('ava_batchid') + '&ava_status=' + nlapiGetFieldValue('ava_status') + '&ava_liststart=0&ava_oldstatus=8&ava_linecount=0'; 1917 window.location = URL1;1918 } 1919}19201921function AVA_ReconcileTaxHeader(security)1922{1923 var soap = null;1924 soap = '\t<soap:Header>\n';1925 soap += security;1926 soap += '\t\t<Profile xmlns="http://avatax.avalara.com/services">\n';1927 soap += '\t\t\t<Name><![CDATA[6.0]]></Name>\n';1928 soap += '\t\t\t<Client><![CDATA[' + AVA_ClientAtt + ']]></Client>\n';1929 soap += '\t\t\t<Adapter/>\n';1930 soap += '\t\t\t<Machine/>\n';1931 soap += '\t\t</Profile>\n';1932 soap += '\t</soap:Header>\n';1933 return soap;1934}19351936/////////////////////////////////////////////////////////////////////////////////////////////////1937/////////////////////////////////////////////////////////////////////////////////////////////////1938// End of Second Suitelet1939/////////////////////////////////////////////////////////////////////////////////////////////////1940///////////////////////////////////////////////////////////////////////////////////////////////// 1941194219431944
...
AVA_PostCommitFunctions.js
Source:AVA_PostCommitFunctions.js
1/******************************************************************************************************2 Script Name - AVA_PostCommitFunctions.js3 Company - Avalara Technologies Pvt Ltd.4******************************************************************************************************/56{7 var AVA_PrevFlag, AVA_NextFlag, AVA_EndPage, AVA_LineCount, recordIdArray, recordObjArray;8}910function AVA_ConfigValidate(request, response)11{12 if(request.getMethod() == 'GET')13 {14 var WebService = nlapiGetContext().getSetting('FEATURE', 'webservicesexternal');15 var AcctPeriod = nlapiGetContext().getSetting('FEATURE', 'accountingperiods');16 17 if(WebService == 'F' || AcctPeriod == 'F')18 {19 var AVA_Message = 'To use this functionality, NetSuite Web Services and Accounting Periods feature needs to be enabled. Please contact the administrator';20 var AVA_Notice = AVA_NoticePage(AVA_Message);21 response.write(AVA_Notice);22 }23 else24 {25 var AVA_Admin;26 var form = nlapiCreateForm('Post & Commit Tax');27 form.setTitle('AvaTax Transactions Commit List');28 form.setScript('customscript_avageneralscript_client');29 30 var AVA_AdminPassword = form.addField('ava_adminpassword', 'password', 'Enter the Administrator Password');31 AVA_AdminPassword.setMandatory(true);32 33 form.addPageLink('breadcrumb', 'Commit Transactions', nlapiResolveURL('SUITELET', 'customscript_avaconfigpassword_suitlet', 'customdeploy_postcommit1'));34 form.addSubmitButton('Submit');35 form.addResetButton('Reset');36 response.writePage(form);37 }38 }39 else40 {41 nlapiGetContext().setSetting('SESSION', 'StartDate', '');42 nlapiGetContext().setSetting('SESSION', 'EndDate', '');43 nlapiGetContext().setSetting('SESSION', 'DocType', '');44 45 var AVA_Message = 'Login Failed. Re-enter the correct administrator password and try again';46 var ValidatePassword = AVA_ValidatePassword(request.getParameter('ava_adminpassword'));47 if (ValidatePassword == 0)48 {49 if (AVA_GetAccountingPeriods() == 0)50 {51 //Logout from NetSuite Web Services52 var NetSuiteLogout = AVA_NetSuiteLogout();53 54 var soapHead2 = new Array();55 soapHead2['Content-Type'] = 'text/xml; charset=utf-8'; 56 soapHead2['Cookie'] = 'NS_VER=2008.1.0; ' + nlapiGetContext().getSetting('SESSION', 'JSessionID');57 soapHead2['SOAPAction'] = '"logout"';58 59 var response3 = nlapiRequestURL('https://webservices.netsuite.com/services/NetSuitePort_2_6' , NetSuiteLogout, soapHead2);60 if(response3.getCode() == 200)61 {62 var soapText3 = response3.getBody();63 var soapXML3 = nlapiStringToXML(soapText3);64 65 var LogoutStatus = nlapiSelectValue(soapXML3, "//@isSuccess");66 if(LogoutStatus == 'false')67 {68 // Redirect to error page69 nlapiLogExecution('DEBUG', 'Please contact the system administrator');70 var AVA_Notice = AVA_NoticePage(AVA_Message);71 response.write(AVA_Notice);72 } 73 }74 // Redirect to Post & Commit Tax Page75 nlapiSetRedirectURL('SUITELET', 'customscript_avapostcommit_suitlet', 'customdeploy_postcommit');76 }77 else78 {79 var AVA_Notice = AVA_NoticePage(AVA_Message);80 response.write(AVA_Notice);81 } 82 }83 else84 {85 var AVA_Notice = AVA_NoticePage(AVA_Message);86 response.write(AVA_Notice);87 }88 }89}9091function AVA_ValidatePassword(AVA_LogPasswd)92{93 var AVA_Test = null;94 var TaxCodeName, TaxCodeGroup, cnt, Xpath ;95 var NetSuiteLogin = AVA_NetSuiteLogin(AVA_LogPasswd);96 97 var soapHead = new Array();98 soapHead['Content-Type'] = 'text/xml; charset=utf-8'; 99 soapHead['SOAPAction'] = '"login"';100101 try102 {103 var response = nlapiRequestURL('https://webservices.netsuite.com/services/NetSuitePort_2_6' , NetSuiteLogin, soapHead);104 if(response.getCode() == 200)105 {106 JSessionID = response.getHeader('Set-Cookie');107 JSessionID = JSessionID.substr(0, JSessionID.indexOf(';', 0)) + ';';108 var soapText = response.getBody();109 var soapXML = nlapiStringToXML(soapText);110 111 var LoginStatus = nlapiSelectValue(soapXML, "//@isSuccess");112 if(LoginStatus == 'true')113 {114 nlapiGetContext().setSetting('SESSION', 'JSessionID' , JSessionID);115 nlapiGetContext().setSetting('SESSION', 'AVA_LogPasswd' , AVA_LogPasswd);116 return 0; // Success117 }118 else119 {120 nlapiLogExecution('DEBUG', 'Please contact the administrator');121 return 1; //Failure122 }123 }124 else125 {126 nlapiLogExecution('DEBUG', 'Re-enter the correct password and submit again');127 return 1; // Failure128 }129 }130 131 catch(err)132 {133 nlapiLogExecution('DEBUG', 'Error - ', err.getStackTrace());134 return 1; // Failure135 }136}137138function AVA_GetAccountingPeriods()139{140 var NetSuitePeriods = AVA_GetNetSuiteAccountingPeriods();141 142 var soapHead1 = new Array();143 soapHead1['Content-Type'] = 'text/xml; charset=utf-8'; 144 soapHead1['Cookie'] = 'NS_VER=2008.1.0; ' + nlapiGetContext().getSetting('SESSION', 'JSessionID');145 soapHead1['SOAPAction'] = '"getSelectValue"';146147 try148 {149 var response1 = nlapiRequestURL('https://webservices.netsuite.com/services/NetSuitePort_2_6' , NetSuitePeriods, soapHead1);150 if(response1.getCode() == 200)151 {152 var soapText1 = response1.getBody();153 var soapXML1 = nlapiStringToXML(soapText1);154155 var PeriodStatus = nlapiSelectValue(soapXML1, "//@isSuccess");156 if(PeriodStatus == 'true')157 {158 var cntrecords = nlapiSelectValue(soapXML1, "//*[name()='ns2:totalRecords']");159 if(cntrecords > 0)160 {161 // Delete all the data in custom records162 var searchresult = nlapiSearchRecord('customrecord_avaacctperiods', null, null, null);163 for(var i=0; searchresult != null && i < searchresult.length; i++)164 {165 nlapiDeleteRecord('customrecord_avaacctperiods', searchresult[i].getId());166 }167 }168169 var periodinternalid = nlapiSelectValues(soapXML1, "//@internalId");170 var periodid = nlapiSelectValues(soapXML1, "//*[name()='ns2:name']");171 172 for(var i=0; i < cntrecords; i++)173 {174 // Populate the data into custom records by reading the xml file.175 var recid = nlapiCreateRecord('customrecord_avaacctperiods');176 recid.setFieldValue('custrecord_ava_periodid', periodinternalid[i]);177 recid.setFieldValue('custrecord_ava_periodname', periodid[i]);178 var subid = nlapiSubmitRecord(recid, false);179 }180 }181 else182 {183 return 1;184 }185 }186 else187 {188 nlapiLogExecution('DEBUG', 'Re-enter the correct password and submit again');189 return 1; // Failure190 }191 }192 193 catch(err)194 {195 nlapiLogExecution('DEBUG', 'Error Catch BLock - ', err.getStackTrace());196 return 1; // Failure197 }198 return 0;199}200201function AVA_NetSuiteLogin(AVA_LogPasswd)202{203 var soap = null;204 soap = '<?xml version="1.0" encoding="UTF-8"?>\n';205 soap += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n';206 soap += '\t<soapenv:Body>\n';207 soap += '\t\t<login xmlns="urn:messages_2_6.platform.webservices.netsuite.com">\n';208 soap += '\t\t\t<passport>\n';209 soap += '\t\t\t\t<ns1:email xmlns:ns1="urn:core_2_6.platform.webservices.netsuite.com">' + nlapiGetContext().getEmail() + '</ns1:email>\n';210 soap += '\t\t\t\t<ns2:password xmlns:ns2="urn:core_2_6.platform.webservices.netsuite.com">' + AVA_LogPasswd + '</ns2:password>\n';211 soap += '\t\t\t\t<ns3:account xmlns:ns3="urn:core_2_6.platform.webservices.netsuite.com">' + nlapiGetContext().getCompany() + '</ns3:account>\n';212 soap += '\t\t\t\t<ns4:role internalId="' + nlapiGetContext().getRole() + '" xmlns:ns4="urn:core_2_6.platform.webservices.netsuite.com"/>\n';213 soap += '\t\t\t</passport>\n';214 soap += '\t\t</login>\n';215 soap += '\t</soapenv:Body>\n';216 soap += '</soapenv:Envelope>';217 return soap;218}219220function AVA_GetNetSuiteAccountingPeriods()221{222 var soap = null;223 soap = '<?xml version="1.0" encoding="utf-8"?>\n';224 soap += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n';225 soap += '\t<soapenv:Header>\n';226 soap += '\t\t<ns1:preferences soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns1="urn:messages.platform.webservices.netsuite.com">\n';227 soap += '\t\t\t<ns2:disableSystemNotesForCustomFields xmlns:ns2="urn:messages_2_6.platform.webservices.netsuite.com">true</ns2:disableSystemNotesForCustomFields>\n';228 soap += '\t\t\t<ns3:ignoreReadOnlyFields xmlns:ns3="urn:messages_2_6.platform.webservices.netsuite.com">true</ns3:ignoreReadOnlyFields>\n';229 soap += '\t\t</ns1:preferences>\n';230 soap += '\t\t<ns4:searchPreferences soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns4="urn:messages.platform.webservices.netsuite.com">\n';231 soap += '\t\t\t<ns5:bodyFieldsOnly xmlns:ns5="urn:messages_2_6.platform.webservices.netsuite.com">false</ns5:bodyFieldsOnly>\n';232 soap += '\t\t\t<ns6:pageSize xmlns:ns6="urn:messages_2_6.platform.webservices.netsuite.com">100</ns6:pageSize>\n';233 soap += '\t\t</ns4:searchPreferences>\n';234 soap += '\t</soapenv:Header>\n';235 soap += '\t<soapenv:Body>\n';236 soap += '\t\t<getSelectValue xmlns="urn:messages_2_6.platform.webservices.netsuite.com">\n';237 soap += '\t\t\t<fieldName fieldType="inventoryAdjustment_postingPeriod"/>\n';238 soap += '\t\t</getSelectValue>\n';239 soap += '\t</soapenv:Body>\n';240 soap += '</soapenv:Envelope>';241 return soap;242}243244function AVA_NetSuiteLogout()245{246 var soap = null;247 soap = '<?xml version="1.0" encoding="utf-8"?>\n';248 soap += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n';249 soap += '\t<soapenv:Header>\n';250 soap += '\t\t<ns1:preferences soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns1="urn:messages.platform.webservices.netsuite.com">\n';251 soap += '\t\t\t<ns2:disableSystemNotesForCustomFields xmlns:ns2="urn:messages_2_6.platform.webservices.netsuite.com">true</ns2:disableSystemNotesForCustomFields>\n';252 soap += '\t\t\t<ns3:ignoreReadOnlyFields xmlns:ns3="urn:messages_2_6.platform.webservices.netsuite.com">true</ns3:ignoreReadOnlyFields>\n';253 soap += '\t\t</ns1:preferences>\n';254 soap += '\t\t<ns4:searchPreferences soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns4="urn:messages.platform.webservices.netsuite.com">\n';255 soap += '\t\t<ns5:bodyFieldsOnly xmlns:ns5="urn:messages_2_6.platform.webservices.netsuite.com">false</ns5:bodyFieldsOnly>\n';256 soap += '\t\t<ns6:pageSize xmlns:ns6="urn:messages_2_6.platform.webservices.netsuite.com">50</ns6:pageSize>\n';257 soap += '\t</ns4:searchPreferences>\n';258 soap += '\t</soapenv:Header>\n';259 soap += '\t<soapenv:Body>\n';260 soap += '\t\t<logout xmlns="urn:messages_2_6.platform.webservices.netsuite.com"/>\n';261 soap += '\t</soapenv:Body>\n';262 soap += '</soapenv:Envelope>';263264 return soap;265}266267function AVA_PostCommit(request, response)268{269 if(request.getMethod() == 'GET')270 {271 var AVA_PostCommitForm = nlapiCreateForm('AvaTax Transactions Commit List');272 AVA_PostCommitForm.setTitle('AvaTax Transactions Commit List');273 AVA_PostCommitForm.setScript('customscript_avapostcommit_client');274 275 var DateFrom = AVA_PostCommitForm.addField('ava_startingdate', 'date', 'Starting Date');276 DateFrom.setDefaultValue(nlapiGetContext().getSetting('SESSION', 'StartDate'));277 DateFrom.setMandatory(true);278 279 var DateTo = AVA_PostCommitForm.addField('ava_endingdate', 'date', 'Ending Date');280 DateTo.setDefaultValue(nlapiGetContext().getSetting('SESSION', 'EndDate'));281 DateTo.setMandatory(true);282 283 var DateFormat = AVA_PostCommitForm.addField('ava_dateformat', 'text', 'Date Format');284 DateFormat.setDefaultValue(nlapiGetContext().getSetting('PREFERENCE', 'DATEFORMAT'));285 DateFormat.setMandatory(true);286 DateFormat.setDisplayType('hidden');287 288 var DocType = AVA_PostCommitForm.addField('ava_doctype', 'select', 'Document Types');289 DocType.addSelectOption('', '');290 DocType.addSelectOption('1', 'Invoice');291 DocType.addSelectOption('2', 'Cash Sale');292 DocType.addSelectOption('3', 'Credit Memo');293 DocType.addSelectOption('4', 'Cash Refund');294 DocType.setDefaultValue(nlapiGetContext().getSetting('SESSION', 'DocType'));295 DocType.setMandatory(true);296 297 if((nlapiGetContext().getSetting('SESSION', 'StartDate') != null) && (nlapiGetContext().getSetting('SESSION', 'StartDate').length > 0))298 {299 DateFrom.setDisplayType('disabled');300 DateTo.setDisplayType('disabled');301 DocType.setDisplayType('disabled');302 303 var AVA_TransactionList = AVA_PostCommitForm.addSubList('custpage_avatranslist', 'list', 'AvaTax Transactions', null); 304 AVA_TransactionList.addField('avainternalid', 'text', 'Internal Id', null);305 AVA_TransactionList.addField('avacommitmap', 'checkbox', 'Apply', null);306 AVA_TransactionList.addField('avatransid', 'text', 'AvaTax Transaction Id', null);307 AVA_TransactionList.addField('avadocno', 'text', 'AvaTax Document Number', null);308 AVA_TransactionList.addField('avadocdate', 'date', 'Document Date', null);309 AVA_TransactionList.addField('avanetdocno', 'text', 'NetSuite Document Number', null);310 AVA_TransactionList.addField('avataxdate', 'date', 'Tax Calculation Date', null);311 AVA_TransactionList.addField('avatotamt', 'currency', 'Total Amount', null);312 AVA_TransactionList.addField('avatotdisc', 'currency', 'Total Discount', null);313 AVA_TransactionList.addField('avatotnontax', 'currency', 'Total Non-Taxable', null);314 AVA_TransactionList.addField('avatottaxable', 'currency', 'Total Taxable', null);315 AVA_TransactionList.addField('avatottax', 'currency', 'Total Tax', null);316 317 AVA_TransactionList.getField('avainternalid').setDisplayType('hidden');318 AVA_TransactionList.addMarkAllButtons();319 AVA_PostCommitForm.addSubmitButton('Submit');320 321 var GetData = AVA_GetRecordsData(nlapiGetContext().getSetting('SESSION', 'StartDate'), nlapiGetContext().getSetting('SESSION', 'EndDate'), nlapiGetContext().getSetting('SESSION', 'DocType'), AVA_TransactionList);322 }323 else324 {325 AVA_PostCommitForm.addSubmitButton('Get Records');326 }327 AVA_PostCommitForm.addPageLink('breadcrumb', 'Commit Transactions', nlapiResolveURL('SUITELET', 'customscript_avaconfigpassword_suitlet', 'customdeploy_postcommit1'));328 AVA_PostCommitForm.addResetButton('Reset');329 nlapiGetContext().setSetting('SESSION', 'StartDate', '');330 nlapiGetContext().setSetting('SESSION', 'EndDate', '');331 nlapiGetContext().setSetting('SESSION', 'DocType', '');332 response.writePage(AVA_PostCommitForm);333 334 }335 else336 {337 var scheduler = 'F';338 if(request.getLineItemCount('custpage_avatranslist') == -1)339 { 340 nlapiGetContext().setSetting('SESSION', 'StartDate', request.getParameter('ava_startingdate'));341 nlapiGetContext().setSetting('SESSION', 'EndDate', request.getParameter('ava_endingdate'));342 nlapiGetContext().setSetting('SESSION', 'DateFormat', request.getParameter('ava_dateformat'));343 nlapiGetContext().setSetting('SESSION', 'DocType', request.getParameter('ava_doctype'));344 345 nlapiSetRedirectURL('SUITELET', 'customscript_avapostcommit_suitlet', 'customdeploy_postcommit');346 }347 else348 {349 for(var i=0; i < request.getLineItemCount('custpage_avatranslist'); i++)350 {351 if(request.getLineItemValue('custpage_avatranslist', 'avacommitmap', i+1) == 'T')352 {353 var RecordId = request.getLineItemValue('custpage_avatranslist', 'avainternalid', i+1);354 nlapiSubmitField('customrecord_avataxheaderdetails', RecordId, 'custrecord_ava_scheduled', 'T');355 scheduler = 'T';356 } 357 }358 359 if(scheduler == 'T')360 {361 var ttt = nlapiScheduleScript('customscript_avapostcommit_scheduled', 'customdeploy_postcommit');362 } 363 nlapiSetRedirectURL('TASKLINK', 'CARD_-29');364 }365 }366}367368function AVA_GetRecordsData(StartDate, EndDate, DocType, TransactionList)369{370 try371 {372 var recordtype;373 switch(DocType)374 {375 case '1':376 recordtype = 'invoice';377 break;378 379 case '2':380 recordtype = 'cashsale';381 break;382 383 case '3':384 recordtype = 'creditmemo';385 break;386 387 case '4':388 recordtype = 'cashrefund';389 break;390 391 default:392 break;393 } 394 395 var Periods = new Array();396 var newsearch = nlapiSearchRecord('customrecord_avaacctperiods', null, null, new nlobjSearchColumn('custrecord_ava_periodid'));397 for(var k=0; newsearch != null && k < newsearch.length; k++)398 {399 Periods[k] = newsearch[k].getValue('custrecord_ava_periodid');400 }401 402 var filters = new Array();403 filters[0] = new nlobjSearchFilter('mainline', null, 'is', 'T');404 filters[1] = new nlobjSearchFilter('trandate', null, 'within', StartDate, EndDate);405 filters[2] = new nlobjSearchFilter('voided', null, 'is', 'F');406 filters[3] = new nlobjSearchFilter('posting', null, 'is', 'T');407 408 var cols = new Array();409 cols[0] = new nlobjSearchColumn('postingperiod');410 411 var searchresult = nlapiSearchRecord(recordtype, null, filters, cols);412 var AVA_DocRecID = new Array();413 414 for(var j =0, k=0; searchresult != null && j < Math.min(1000, searchresult.length); j++)415 {416 var PostPeriod = searchresult[j].getValue('postingperiod');417 var PeriodExists = 'F';418 419 for(var kk = 0; kk < Periods.length; kk++)420 {421 if(PostPeriod == Periods[kk])422 {423 PeriodExists = 'T';424 break;425 }426 }427 428 if(PeriodExists == 'F')429 {430 AVA_DocRecID[k] = String(searchresult[j].getId());431 k++;432 }433 }434 435 var filters = new Array();436 filters[0] = new nlobjSearchFilter('internalid', 'custrecord_ava_documentinternalid', 'anyof', AVA_DocRecID);437 filters[1] = new nlobjSearchFilter('custrecord_ava_documentstatus', null, 'equalto', 1);438 filters[2] = new nlobjSearchFilter('custrecord_ava_netsuitedoctype', null, 'is', nlapiGetContext().getSetting('SESSION', 'DocType'));439 filters[3] = new nlobjSearchFilter('custrecord_ava_scheduled', null, 'is', 'F');440 filters[4] = new nlobjSearchFilter('mainline', 'custrecord_ava_documentinternalid', 'is', 'T'); 441 442 var cols = new Array();443 cols[0] = new nlobjSearchColumn('custrecord_ava_documentid');444 cols[1] = new nlobjSearchColumn('custrecord_ava_documentinternalid');445 cols[2] = new nlobjSearchColumn('custrecord_ava_documentno');446 cols[3] = new nlobjSearchColumn('custrecord_ava_taxcalculationdate');447 cols[4] = new nlobjSearchColumn('custrecord_ava_totalamount');448 cols[5] = new nlobjSearchColumn('custrecord_ava_totaldiscount');449 cols[6] = new nlobjSearchColumn('custrecord_ava_totalnontaxable');450 cols[7] = new nlobjSearchColumn('custrecord_ava_totaltaxable');451 cols[8] = new nlobjSearchColumn('custrecord_ava_totaltax');452 cols[9] = new nlobjSearchColumn('custrecord_ava_documentstatus');453 cols[10] = new nlobjSearchColumn('custrecord_ava_documentdate');454455 var Multiplier = nlapiGetContext().getSetting('SESSION', 'DocType');456 Multiplier = (Multiplier <= 2)? 1 : 1;457458 var searchresult1 = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);459 460 for(var i = 0; searchresult1 != null && i < searchresult1.length; i++)461 {462 TransactionList.setLineItemValue('avainternalid', i+1, searchresult1[i].getId());463 TransactionList.setLineItemValue('avacommitmap', i+1, 'F');464 465 TransactionList.setLineItemValue('avadocno', i+1, searchresult1[i].getValue('custrecord_ava_documentinternalid'));466 467 var URL1 = nlapiResolveURL('SUITELET', 'customscript_avagettaxhistory_suitelet', 'customdeploy_gettaxhistory', false);468 URL1 = URL1 + '&doctype=' + DocType +'&doccode=' + searchresult1[i].getValue('custrecord_ava_documentinternalid');469 var FinalURL = '<a href="' + URL1 + '" target="_blank">' + searchresult1[i].getValue('custrecord_ava_documentno') + '</a>';470471 TransactionList.setLineItemValue('avanetdocno', i+1, FinalURL);472 TransactionList.setLineItemValue('avadocdate', i+1, searchresult1[i].getValue('custrecord_ava_documentdate'));473 474 TransactionList.setLineItemValue('avataxdate', i+1, searchresult1[i].getValue('custrecord_ava_taxcalculationdate'));475476 var Totalamount = parseFloat(searchresult1[i].getValue('custrecord_ava_totalamount'));477 Totalamount = (Totalamount != 0)? Totalamount * Multiplier: Totalamount;478 TransactionList.setLineItemValue('avatotamt', i+1, Totalamount);479480 var Totaldiscount = parseFloat(searchresult1[i].getValue('custrecord_ava_totaldiscount'));481 Totaldiscount = (Totaldiscount != 0)? Totaldiscount * Multiplier: Totaldiscount;482 TransactionList.setLineItemValue('avatotdisc', i+1, Totaldiscount);483484 var Totalnontaxable = parseFloat(searchresult1[i].getValue('custrecord_ava_totalnontaxable'));485 Totalnontaxable = (Totalnontaxable != 0)? Totalnontaxable * Multiplier: Totalnontaxable;486 TransactionList.setLineItemValue('avatotnontax', i+1, Totalnontaxable);487488 var Totaltaxable = parseFloat(searchresult1[i].getValue('custrecord_ava_totaltaxable'));489 Totaltaxable = (Totaltaxable != 0)? Totaltaxable * Multiplier: Totaltaxable;490 TransactionList.setLineItemValue('avatottaxable', i+1, Totaltaxable);491492 var Totaltax = parseFloat(searchresult1[i].getValue('custrecord_ava_totaltax'));493 Totaltax = (Totaltax != 0)? Totaltax * Multiplier: Totaltax;494 TransactionList.setLineItemValue('avatottax', i+1, Totaltax);495 }496 }497 catch(err)498 {499 nlapiLogExecution('DEBUG', 'Post & Commit', 'Please contact administrator for further information');500 nlapiGetContext().setSetting('SESSION', 'StartDate', '');501 nlapiGetContext().setSetting('SESSION', 'EndDate', '');502 nlapiGetContext().setSetting('SESSION', 'DocType', '');503 } 504 return 0;505}506507function AVA_PostCommit_Save()508{509 var Linecount = nlapiGetLineItemCount('custpage_avatranslist'); 510 if(Linecount >= 0)511 {512 var AVA_MapExists = 'F';513 for(var i=0 ; i < nlapiGetLineItemCount('custpage_avatranslist'); i++)514 {515 if(nlapiGetLineItemValue('custpage_avatranslist', 'avacommitmap', i+1) == 'T')516 {517 AVA_MapExists = 'T';518 break;519 }520 }521 522 if(AVA_MapExists == 'F' && Linecount != 0)523 {524 alert('Select records to Commit and then try submitting');525 return false;526 }527 else528 {529 return true;530 }531 }532 else533 {534 return AVA_ValidateData();535 }536 537}538539function AVA_ValidateData()540{541 var StartDate = nlapiGetFieldValue('ava_startingdate');542 var EndDate = nlapiGetFieldValue('ava_endingdate');543 var DateFormat = nlapiGetFieldValue('ava_dateformat');544545 if(StartDate.length == 0)546 {547 alert('Select Starting Date');548 return false;549 }550 551 if(EndDate.length == 0)552 {553 alert('Select Ending Date');554 return false;555 }556 557 StartDate = new Date(AVA_FormatDate(DateFormat,StartDate));558 EndDate = new Date(AVA_FormatDate(DateFormat,EndDate));559 560 if(EndDate < StartDate)561 {562 alert('Ending Date should be greater than or equal to Start Date');563 return false;564 }565 566 if(nlapiGetFieldValue('ava_doctype').length == 0)567 {568 alert('Select a document type');569 return false;570 }571572 return true;573}574575function AVA_PostandCommitTax()576{577 var searchresult = nlapiSearchRecord('customrecord_avaconfig', null, null, null);578 for(var i=0; searchresult != null && i < searchresult.length; i++)579 {580 var record = nlapiLoadRecord('customrecord_avaconfig', searchresult[i].getId());581 var loadvalues = AVA_LoadValuesToGlobals(record);582 }583584 var filters = new Array();585 filters[0] = new nlobjSearchFilter('custrecord_ava_scheduled', null, 'is', 'T');586 587 var cols = new Array();588 cols[0] = new nlobjSearchColumn('custrecord_ava_documentid');589 cols[1] = new nlobjSearchColumn('custrecord_ava_documenttype');590 cols[2] = new nlobjSearchColumn('custrecord_ava_documentinternalid');591 cols[3] = new nlobjSearchColumn('custrecord_ava_documentdate');592 cols[4] = new nlobjSearchColumn('custrecord_ava_totalamount');593 cols[5] = new nlobjSearchColumn('custrecord_ava_totaltax');594 595 var searchresult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);596 for(var i=0; searchresult != null && i < searchresult.length; i++)597 {598 var AVA_DocType = searchresult[i].getValue('custrecord_ava_documenttype');599 600 switch(AVA_DocType)601 {602 case '2':603 AVA_DocType = 'SalesInvoice';604 break;605 606 case '4':607 AVA_DocType = 'PurchaseInvoice';608 break;609 610 case '6':611 AVA_DocType = 'ReturnInvoice';612 break;613 614 default:615 break;616 }617618 var AVA_TransID = searchresult[i].getValue('custrecord_ava_documentinternalid');619 var AVA_DocDate = AVA_GetDate(searchresult[i].getValue('custrecord_ava_documentdate'), nlapiGetContext().getSetting('PREFERENCE', 'DATEFORMAT')); 620 var AVA_TotAmt = searchresult[i].getValue('custrecord_ava_totalamount');621 var AVA_TotTax = searchresult[i].getValue('custrecord_ava_totaltax');622 623 var security = AVA_TaxSecurity(AVA_AccountValue, AVA_LicenseKey);624 var headers = AVA_TaxHeader(security);625 var body = AVA_PostTaxBody(AVA_DocType, AVA_TransID, AVA_DocDate, AVA_TotAmt, AVA_TotTax);626 var soapPayload = AVA_GetTaxEnvelope(headers + body);627628 var soapHead = new Array();629 soapHead['Content-Type'] = 'text/xml';630 soapHead['SOAPAction'] = 'http://avatax.avalara.com/services/PostTax';631 632 var response = nlapiRequestURL(AVA_ServiceUrl + '/tax/taxsvc.asmx', soapPayload, soapHead);633 if (response.getCode() == 200)634 {635 var soapText = response.getBody();636 var soapXML = nlapiStringToXML(soapText);637638 var PostTaxResult = nlapiSelectNode(soapXML, "//*[name()='PostTaxResult']");639 var ResultCode = nlapiSelectValue( PostTaxResult, "//*[name()='ResultCode']");640 641 var fields = new Array();642 fields[0] = 'custrecord_ava_documentstatus';643 fields[1] = 'custrecord_ava_scheduled';644645 if (ResultCode == 'Success')646 {647 var values = new Array(); 648 values[0] = 3;649 values[1] = 'F'; 650 nlapiSubmitField('customrecord_avataxheaderdetails', searchresult[i].getId(), fields, values);651 }652 else if(ResultCode == 'Warning')653 {654 var values = new Array(); 655 values[0] = 3;656 values[1] = 'F'; 657658 nlapiLogExecution('DEBUG', 'AvaTax Document Id', AVA_DocId);659 var AVA_Message = nlapiSelectValues( soapXML, "//*[name()='Summary']");660 for(var k=0; k < AVA_Message.length; k++)661 {662 nlapiLogExecution('DEBUG', ResultCode , AVA_Message[k]);663 }664 nlapiSubmitField('customrecord_avataxheaderdetails', searchresult[i].getId(), fields, values);665 }666 else if(ResultCode == 'Error' || ResultCode == 'Exception')667 {668 var values = new Array(); 669 values[0] = 1;670 values[1] = 'F'; 671672 var AVA_Message = nlapiSelectValues( soapXML, "//*[name()='Summary']");673 nlapiLogExecution('DEBUG', 'AvaTax Document Id', AVA_DocId);674 for(var k=0; k < AVA_Message.length; k++)675 {676 nlapiLogExecution('DEBUG', ResultCode , AVA_Message[k]);677 }678 nlapiSubmitField('customrecord_avataxheaderdetails', searchresult[i].getId(), fields, values);679 }680 }681 else682 {683 nlapiLogExecution('DEBUG', 'Contact the administrator for further details');684 }685 }686}687688function AVA_PostTaxBody(AVA_DocType, AVA_TransID, AVA_DocDate, AVA_TotAmt, AVA_TotTax)689{690 var soap = null;691 var Multiplier = (AVA_DocType == 'SalesInvoice')? 1 : -1;692 693 soap = '\t<soap:Body>\n';694 soap += '\t\t<PostTax xmlns="http://avatax.avalara.com/services">\n';695 soap += '\t\t\t<PostTaxRequest>\n';696 soap += '\t\t\t\t<CompanyCode><![CDATA[' + nlapiGetContext().getCompany() + ']]></CompanyCode>\n';697 soap += '\t\t\t\t<DocType><![CDATA[' + AVA_DocType + ']]></DocType>\n';698 soap += '\t\t\t\t<DocCode><![CDATA[' + AVA_TransID + ']]></DocCode>\n';699 soap += '\t\t\t\t<DocDate>' + AVA_DocDate + '</DocDate>\n';700 soap += '\t\t\t\t<TotalAmount>' + AVA_TotAmt + '</TotalAmount>\n';701 soap += '\t\t\t\t<TotalTax>' + AVA_TotTax + '</TotalTax>\n';702 soap += '\t\t\t\t<Commit>1</Commit>\n';703 soap += '\t\t\t</PostTaxRequest>\n'; 704 soap += '\t\t</PostTax>\n'; 705 soap += '\t</soap:Body>\n';706 return soap;707}708709function AVA_UncommittedList(request, response)710{711 recordIdArray = new Array();712 recordObjArray= new Array();713 714 var AVA_TransactionForm = nlapiCreateForm('AvaTax Uncommitted Transaction List');715 AVA_TransactionForm.setTitle('AvaTax Uncommitted Transactions List');716 717 var AVA_Tab = AVA_TransactionForm.addTab('custpage_avatab', '');718 719 var AVA_TransactionList = AVA_BodyFields(AVA_TransactionForm, AVA_Tab);720721 var filters = new Array();722 filters[0] = new nlobjSearchFilter('custrecord_ava_documentstatus', null, 'equalto', 1);723 724 var cols = AVA_SearchColumns();725 726 var searchresult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);727 for( ; searchresult != null; )728 {729 for(var k=0; searchresult != null && k<searchresult.length; k++)730 {731 try732 {733 recordIdArray[recordIdArray.length] = searchresult[k].getId();734 recordObjArray[recordObjArray.length] = searchresult[k];735 }736 catch(err)737 {738 }739 }740 741 filters[1] = new nlobjSearchFilter('internalid',null, 'noneof', recordIdArray);742 743 searchresult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);744 }745 746 if(recordObjArray != null)747 {748 var ListStart = AVA_ResultsList(AVA_TransactionList);749 750 var FirstLink = '<<First Page';751 var PrevLink = 'Previous';752 var NextLink = 'Next';753 var LastLink = 'Last Page>>';754 755 //First Page756 if(AVA_PrevFlag == 'T')757 {758 var URL1 = nlapiResolveURL('SUITELET', 'customscript_avauncommittedlist_suitlet', 'customdeploy_uncommittedlist', false);759 URL1 = URL1 + '&ava_liststart=0';760 761 FirstLink = '<b><a href="'+ URL1 +'">\t\t\t\t<<First Page</a></b>';//>762 } 763 764 //Previous765 if(AVA_PrevFlag == 'T')766 {767 var URL1 = nlapiResolveURL('SUITELET', 'customscript_avauncommittedlist_suitlet', 'customdeploy_uncommittedlist', false);768 URL1 = URL1 + '&ava_liststart='+ ListStart + '&ava_flag=F' + '&ava_linecount=' + AVA_LineCount;769 770 PrevLink = '<b> <a href="'+ URL1 +'">Previous</a></b>';771 }772 773 //Next774 if(AVA_NextFlag == 'T')775 {776 URL1 = nlapiResolveURL('SUITELET', 'customscript_avauncommittedlist_suitlet', 'customdeploy_uncommittedlist', false);777 URL1 = URL1 + '&ava_liststart=' + ListStart + '&ava_flag=T' + '&ava_linecount=' + AVA_LineCount;778 779 NextLink = '<b> <a href="'+ URL1 +'">Next</a></b>';780 }781 782 //Last Page783 if(AVA_NextFlag == 'T')784 {785 URL1 = nlapiResolveURL('SUITELET', 'customscript_avauncommittedlist_suitlet', 'customdeploy_uncommittedlist', false);786 URL1 = URL1 + '&ava_liststart=' + AVA_EndPage + '&ava_linecount=' + AVA_LineCount;787 788 LastLink = '<b> <a href="'+ URL1 +'">Last Page>></a></b>';789 } 790 791 AVA_TransactionForm.addField('ava_star','help','(*) indicates Transactions deleted from NetSuite').setLayoutType('outsidebelow','startrow');792 var emptyCells = '<td></td><td></td><td></td><td></td><td></td><td></td><td></td>';793 var html = '<table cellspacing="20" align="center"><tr>' + emptyCells + emptyCells +'<td><font size="1">' + FirstLink+ '</font></td><td><font size="1">| ' + PrevLink + '</font></td>';794 html +='<td><font size="1">| ' + NextLink + ' |</font></td><td><font size="1">' + LastLink+ '</font></td></tr></table>';795 var PagingHtml = AVA_TransactionForm.addField('ava_pagelinks', 'help', html, null, AVA_Tab);796 PagingHtml.setLayoutType('outsidebelow','startrow');797 }798 799 AVA_TransactionForm.addPageLink('breadcrumb', 'Uncommitted Transactions', nlapiResolveURL('SUITELET', 'customscript_avauncommittedlist_suitlet', 'customdeploy_uncommittedlist'));800 response.writePage(AVA_TransactionForm);801}802803function AVA_CommittedList(request, response)804{805 if(AVA_CheckService('TaxSvc') == 0 && AVA_CheckSecurity( 1 ) == 0)806 {807 recordIdArray = new Array();808 recordObjArray= new Array();809 810 var AVA_TransactionForm = nlapiCreateForm('AvaTax Committed Transaction List');811 AVA_TransactionForm.setTitle('AvaTax Committed Transactions List');812 813 var AVA_Tab = AVA_TransactionForm.addTab('custpage_avatab', '');814 815 var AVA_TransactionList = AVA_BodyFields(AVA_TransactionForm, AVA_Tab);816 817 var filters = new Array();818 filters[0] = new nlobjSearchFilter('custrecord_ava_documentstatus', null, 'equalto', 3);819 820 var cols = AVA_SearchColumns();821 822 var searchresult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);823 824 for( ; searchresult != null; )825 {826 for(var k=0; searchresult != null && k<searchresult.length; k++)827 {828 try829 {830 recordIdArray[recordIdArray.length] = searchresult[k].getId();831 recordObjArray[recordObjArray.length] = searchresult[k];832 }833 catch(err)834 {835 }836 }837 838 filters[1] = new nlobjSearchFilter('internalid',null, 'noneof', recordIdArray);839 840 searchresult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);841 }842 843 if(recordObjArray != null)844 {845 var ListStart = AVA_ResultsList(AVA_TransactionList);846 847 var FirstLink = '<<First Page';848 var PrevLink = 'Previous';849 var NextLink = 'Next';850 var LastLink = 'Last Page>>';851 852 //First Page853 if(AVA_PrevFlag == 'T')854 {855 var URL1 = nlapiResolveURL('SUITELET', 'customscript_avacommittedlist_suitlet', 'customdeploy_avacommittedlist', false);856 URL1 = URL1 + '&ava_liststart=0';857 858 FirstLink = '<b><a href="'+ URL1 +'">\t\t\t\t<<First Page</a></b>';//>859 } 860 861 //Previous862 if(AVA_PrevFlag == 'T')863 {864 var URL1 = nlapiResolveURL('SUITELET', 'customscript_avacommittedlist_suitlet', 'customdeploy_avacommittedlist', false);865 URL1 = URL1 + '&ava_liststart='+ ListStart + '&ava_flag=F' + '&ava_linecount=' + AVA_LineCount;866 867 PrevLink = '<b> <a href="'+ URL1 +'">Previous</a></b>';868 }869 870 //Next871 if(AVA_NextFlag == 'T')872 {873 URL1 = nlapiResolveURL('SUITELET', 'customscript_avacommittedlist_suitlet', 'customdeploy_avacommittedlist', false);874 URL1 = URL1 + '&ava_liststart=' + ListStart + '&ava_flag=T' + '&ava_linecount=' + AVA_LineCount;875 876 NextLink = '<b> <a href="'+ URL1 +'">Next</a></b>';877 }878 879 //Last Page880 if(AVA_NextFlag == 'T')881 {882 URL1 = nlapiResolveURL('SUITELET', 'customscript_avacommittedlist_suitlet', 'customdeploy_avacommittedlist', false);883 URL1 = URL1 + '&ava_liststart=' + AVA_EndPage + '&ava_linecount=' + AVA_LineCount;884 885 LastLink = '<b> <a href="'+ URL1 +'">Last Page>></a></b>';886 } 887 888 AVA_TransactionForm.addField('ava_star','help','(*) indicates Transactions deleted from NetSuite').setLayoutType('outsidebelow','startrow');889 890 var emptyCells = '<td></td><td></td><td></td><td></td><td></td><td></td><td></td>';891 var html = '<table cellspacing="20" align="center"><tr>' + emptyCells + emptyCells +'<td><font size="1">' + FirstLink+ '</font></td><td><font size="1">| ' + PrevLink + '</font></td>';892 html +='<td><font size="1">| ' + NextLink + ' |</font></td><td><font size="1">' + LastLink+ '</font></td></tr></table>';893 var PagingHtml = AVA_TransactionForm.addField('ava_pagelinks', 'help', html, null, AVA_Tab);894 PagingHtml.setLayoutType('outsidebelow','startrow');895 }896 897 AVA_TransactionForm.addPageLink('breadcrumb', 'Committed Transactions', nlapiResolveURL('SUITELET', 'customscript_avacommittedlist_suitlet', 'customdeploy_avacommittedlist'));898 response.writePage(AVA_TransactionForm);899 }900}901902function AVA_VoidedList(request, response)903{904 if(AVA_CheckService('TaxSvc') == 0 && AVA_CheckSecurity( 13 ) == 0)905 {906 recordIdArray = new Array();907 recordObjArray= new Array();908 909 var AVA_TransactionForm = nlapiCreateForm('AvaTax Voided Transaction List');910 AVA_TransactionForm.setTitle('AvaTax Voided Transactions List');911 912 var AVA_Tab = AVA_TransactionForm.addTab('custpage_avatab', '');913 914 var AVA_TransactionList = AVA_BodyFields(AVA_TransactionForm, AVA_Tab);915 916 var filters = new Array();917 filters[0] = new nlobjSearchFilter('custrecord_ava_documentstatus', null, 'equalto', 4);918 919 var cols = AVA_SearchColumns();920 921 var searchresult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);922 923 for( ; searchresult != null; )924 {925 for(var k=0; searchresult != null && k<searchresult.length; k++)926 {927 try928 {929 recordIdArray[recordIdArray.length] = searchresult[k].getId();930 recordObjArray[recordObjArray.length] = searchresult[k];931 }932 catch(err)933 {934 }935 }936 937 filters[1] = new nlobjSearchFilter('internalid',null, 'noneof', recordIdArray);938 939 searchresult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);940 }941 942 if(recordObjArray != null)943 {944 var ListStart = AVA_ResultsList(AVA_TransactionList);945 946 var FirstLink = '<<First Page';947 var PrevLink = 'Previous';948 var NextLink = 'Next';949 var LastLink = 'Last Page>>';950 951 //First Page952 if(AVA_PrevFlag == 'T')953 {954 var URL1 = nlapiResolveURL('SUITELET', 'customscriptavavoidedlist_suitlet', 'customdeploy_avavoidedlist', false);955 URL1 = URL1 + '&ava_liststart=0';956 957 FirstLink = '<b><a href="'+ URL1 +'">\t\t\t\t<<First Page</a></b>';//>958 } 959 960 //Previous961 if(AVA_PrevFlag == 'T')962 {963 var URL1 = nlapiResolveURL('SUITELET', 'customscriptavavoidedlist_suitlet', 'customdeploy_avavoidedlist', false);964 URL1 = URL1 + '&ava_liststart='+ ListStart + '&ava_flag=F' + '&ava_linecount=' + AVA_LineCount;965 966 PrevLink = '<b> <a href="'+ URL1 +'">Previous</a></b>';967 }968 969 //Next970 if(AVA_NextFlag == 'T')971 {972 URL1 = nlapiResolveURL('SUITELET', 'customscriptavavoidedlist_suitlet', 'customdeploy_avavoidedlist', false);973 URL1 = URL1 + '&ava_liststart=' + ListStart + '&ava_flag=T' + '&ava_linecount=' + AVA_LineCount;974 975 NextLink = '<b> <a href="'+ URL1 +'">Next</a></b>';976 }977 978 //Last Page979 if(AVA_NextFlag == 'T')980 {981 URL1 = nlapiResolveURL('SUITELET', 'customscriptavavoidedlist_suitlet', 'customdeploy_avavoidedlist', false);982 URL1 = URL1 + '&ava_liststart=' + AVA_EndPage + '&ava_linecount=' + AVA_LineCount;983 984 LastLink = '<b> <a href="'+ URL1 +'">Last Page>></a></b>';985 } 986 987 AVA_TransactionForm.addField('ava_star','help','(*) indicates Transactions deleted from NetSuite').setLayoutType('outsidebelow','startrow');988 989 var emptyCells = '<td></td><td></td><td></td><td></td><td></td><td></td><td></td>';990 var html = '<table cellspacing="20" align="center"><tr>' + emptyCells + emptyCells +'<td><font size="1">' + FirstLink+ '</font></td><td><font size="1">| ' + PrevLink + '</font></td>';991 html +='<td><font size="1">| ' + NextLink + ' |</font></td><td><font size="1">' + LastLink+ '</font></td></tr></table>';992 var PagingHtml = AVA_TransactionForm.addField('ava_pagelinks', 'help', html, null, AVA_Tab);993 PagingHtml.setLayoutType('outsidebelow','startrow');994 }995 996 AVA_TransactionForm.addPageLink('breadcrumb', 'Voided Transactions', nlapiResolveURL('SUITELET', 'customscriptavavoidedlist_suitlet', 'customdeploy_avavoidedlist'));997 response.writePage(AVA_TransactionForm);998 }999}10001001function AVA_ScheduledList(request, response)1002{1003 recordIdArray = new Array();1004 recordObjArray= new Array();1005 1006 var AVA_TransactionForm = nlapiCreateForm('AvaTax Scheduled Transaction List');1007 AVA_TransactionForm.setTitle('AvaTax Scheduled Transactions List');1008 1009 var AVA_Tab = AVA_TransactionForm.addTab('custpage_avatab', '');1010 1011 var AVA_TransactionList = AVA_BodyFields(AVA_TransactionForm, AVA_Tab);10121013 var filters = new Array();1014 filters[0] = new nlobjSearchFilter('custrecord_ava_scheduled', null, 'is', 'T');1015 1016 var cols = AVA_SearchColumns();10171018 var searchresult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);1019 1020 for( ; searchresult != null; )1021 {1022 for(var k=0; searchresult != null && k<searchresult.length; k++)1023 {1024 try1025 {1026 recordIdArray[recordIdArray.length] = searchresult[k].getId();1027 recordObjArray[recordObjArray.length] = searchresult[k];1028 }1029 catch(err)1030 {1031 }1032 }1033 1034 filters[1] = new nlobjSearchFilter('internalid',null, 'noneof', recordIdArray);1035 1036 searchresult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);1037 }1038 1039 if(recordObjArray != null)1040 {1041 var ListStart = AVA_ResultsList(AVA_TransactionList);1042 1043 var FirstLink = '<<First Page';1044 var PrevLink = 'Previous';1045 var NextLink = 'Next';1046 var LastLink = 'Last Page>>';1047 1048 //First Page1049 if(AVA_PrevFlag == 'T')1050 {1051 var URL1 = nlapiResolveURL('SUITELET', 'customscript_avascheduledlist_suitlet', 'customdeploy_avascheduledlist', false);1052 URL1 = URL1 + '&ava_liststart=0';1053 1054 FirstLink = '<b><a href="'+ URL1 +'">\t\t\t\t<<First Page</a></b>';//>1055 } 1056 1057 //Previous1058 if(AVA_PrevFlag == 'T')1059 {1060 var URL1 = nlapiResolveURL('SUITELET', 'customscript_avascheduledlist_suitlet', 'customdeploy_avascheduledlist', false);1061 URL1 = URL1 + '&ava_liststart='+ ListStart + '&ava_flag=F' + '&ava_linecount=' + AVA_LineCount;1062 1063 PrevLink = '<b> <a href="'+ URL1 +'">Previous</a></b>';1064 }1065 1066 //Next1067 if(AVA_NextFlag == 'T')1068 {1069 URL1 = nlapiResolveURL('SUITELET', 'customscript_avascheduledlist_suitlet', 'customdeploy_avascheduledlist', false);1070 URL1 = URL1 + '&ava_liststart=' + ListStart + '&ava_flag=T' + '&ava_linecount=' + AVA_LineCount;1071 1072 NextLink = '<b> <a href="'+ URL1 +'">Next</a></b>';1073 }1074 1075 //Last Page1076 if(AVA_NextFlag == 'T')1077 {1078 URL1 = nlapiResolveURL('SUITELET', 'customscript_avascheduledlist_suitlet', 'customdeploy_avascheduledlist', false);1079 URL1 = URL1 + '&ava_liststart=' + AVA_EndPage + '&ava_linecount=' + AVA_LineCount;1080 1081 LastLink = '<b> <a href="'+ URL1 +'">Last Page>></a></b>';1082 AVA_TransactionForm.addField('ava_lastpage','help',FinalURL, null, AVA_Tab).setLayoutType('outsidebelow',null); 1083 } 1084 1085 AVA_TransactionForm.addField('ava_star','help','(*) indicates Transactions deleted from NetSuite').setLayoutType('outsidebelow','startrow');1086 1087 var emptyCells = '<td></td><td></td><td></td><td></td><td></td><td></td><td></td>';1088 var html = '<table cellspacing="20" align="center"><tr>' + emptyCells + emptyCells +'<td><font size="1">' + FirstLink+ '</font></td><td><font size="1">| ' + PrevLink + '</font></td>';1089 html +='<td><font size="1">| ' + NextLink + ' |</font></td><td><font size="1">' + LastLink+ '</font></td></tr></table>';1090 var PagingHtml = AVA_TransactionForm.addField('ava_pagelinks', 'help', html, null, AVA_Tab);1091 PagingHtml.setLayoutType('outsidebelow','startrow');1092 }10931094 AVA_TransactionForm.addPageLink('breadcrumb', 'Scheduled Transactions', nlapiResolveURL('SUITELET', 'customscript_avascheduledlist_suitlet', 'customdeploy_avascheduledlist'));1095 response.writePage(AVA_TransactionForm);1096}10971098function AVA_BodyFields(InForm, AVA_Tab)1099{1100 var AVA_TransactionList = InForm.addSubList('custpage_avatranslist', 'list', 'AvaTax Transactions', AVA_Tab); 11011102 AVA_TransactionList.addField('custrecord_ava_documentdate', 'date', 'Document Date', 'LEFT');1103 AVA_TransactionList.addField('custrecord_ava_documentinternalid', 'text', 'AvaTax Document Number', 'LEFT');1104 AVA_TransactionList.addField('custrecord_ava_documentno', 'text', 'NetSuite Document Number', 'LEFT');1105 AVA_TransactionList.addField('custrecord_ava_documenttype', 'text', 'AvaTax Document Type', 'LEFT');1106 AVA_TransactionList.addField('custrecord_ava_netsuitedoctype', 'text', 'NetSuite Document Type', 'LEFT');1107 AVA_TransactionList.addField('custrecord_ava_totalamount', 'currency', 'Total Amount', 'LEFT');1108 AVA_TransactionList.addField('custrecord_ava_totaldiscount', 'currency', 'Total Discount', 'LEFT');1109 AVA_TransactionList.addField('custrecord_ava_totalnontaxable', 'currency', 'Total Non-Taxable', 'LEFT');1110 AVA_TransactionList.addField('custrecord_ava_totaltaxable', 'currency', 'Total Taxable', 'LEFT');1111 AVA_TransactionList.addField('custrecord_ava_totaltax', 'currency', 'Total Tax', 'LEFT');11121113 return AVA_TransactionList;1114}11151116function AVA_SearchColumns()1117{1118 var cols = new Array();1119 cols[0] = new nlobjSearchColumn('custrecord_ava_documentdate');1120 cols[1] = new nlobjSearchColumn('custrecord_ava_documentid');1121 cols[2] = new nlobjSearchColumn('custrecord_ava_documentinternalid');1122 cols[3] = new nlobjSearchColumn('custrecord_ava_documentno');1123 cols[4] = new nlobjSearchColumn('custrecord_ava_documenttype');1124 cols[5] = new nlobjSearchColumn('custrecord_ava_netsuitedoctype');1125 cols[6] = new nlobjSearchColumn('custrecord_ava_totalamount');1126 cols[7] = new nlobjSearchColumn('custrecord_ava_totaldiscount');1127 cols[8] = new nlobjSearchColumn('custrecord_ava_totaltaxable');1128 cols[9] = new nlobjSearchColumn('custrecord_ava_totalnontaxable');1129 cols[10] = new nlobjSearchColumn('custrecord_ava_totaltax');1130 cols[11] = new nlobjSearchColumn('custrecord_ava_basecurrency');1131 cols[12] = new nlobjSearchColumn('custrecord_ava_foreigncurr');1132 cols[13] = new nlobjSearchColumn('custrecord_ava_exchangerate');1133 1134 return cols; 1135}113611371138function AVA_ResultsList(AVA_TransactionList)1139{1140 var RecordCountStart, RecordCountText;1141 var j = (request.getParameter('ava_liststart')==null)? 0 : parseFloat(request.getParameter('ava_liststart'));1142 AVA_LineCount = (request.getParameter('ava_linecount')==null)? 0: parseFloat(request.getParameter('ava_linecount'));1143 1144 var ListLimit = parseFloat(nlapiGetContext().getSetting('PREFERENCE', 'LISTSEGMENTSIZE'));1145 var AVA_Flag = (request.getParameter('ava_flag')==null)? 'T' : request.getParameter('ava_flag');1146 1147 if(AVA_Flag == 'F')1148 {1149 if(AVA_LineCount>0)1150 {1151 if(AVA_LineCount<ListLimit)1152 {1153 MaxLength = parseFloat(ListLimit) + parseFloat(AVA_LineCount);1154 ListStart = j = parseFloat(j) - parseFloat(MaxLength);1155 }1156 else1157 {1158 MaxLength = (parseFloat(ListLimit) * parseFloat(2));1159 ListStart = j = parseFloat(j) - parseFloat(MaxLength);1160 }1161 }11621163 }1164 1165 for(var i=0; recordObjArray != null && i < ListLimit && j<recordObjArray.length && j>=0 ; i++, j++)1166 {1167 AVA_TransactionList.setLineItemValue('custrecord_ava_documentdate', i+1, recordObjArray[j].getValue('custrecord_ava_documentdate'));1168 AVA_TransactionList.setLineItemValue('custrecord_ava_documentinternalid', i+1, (recordObjArray[j].getValue('custrecord_ava_documentinternalid') != null && recordObjArray[j].getValue('custrecord_ava_documentinternalid').length > 0) ? recordObjArray[j].getValue('custrecord_ava_documentinternalid') : '*');1169 1170 var DocType = (recordObjArray[j].getValue('custrecord_ava_documenttype') == 2)? 'SalesInvoice' : 'ReturnInvoice';1171 AVA_TransactionList.setLineItemValue('custrecord_ava_documenttype', i+1, DocType);11721173 var NetDocType;1174 switch(recordObjArray[j].getValue('custrecord_ava_netsuitedoctype'))1175 {1176 case '1':1177 NetDocType = 'Invoice';1178 break;1179 1180 case '2':1181 NetDocType = 'Cash Sale';1182 break;1183 1184 case '3':1185 NetDocType = 'Credit Memo';1186 break;1187 1188 case '4':1189 NetDocType = 'Cash Refund';1190 break;1191 1192 default:1193 break;1194 }1195 1196 if(recordObjArray[j].getValue('custrecord_ava_documentinternalid') != null && recordObjArray[j].getValue('custrecord_ava_documentinternalid').length > 0)1197 {1198 var URL1 = nlapiResolveURL('SUITELET', 'customscript_avagettaxhistory_suitelet', 'customdeploy_gettaxhistory', false);1199 URL1 = URL1 + '&doctype=' + DocType +'&doccode=' + recordObjArray[j].getValue('custrecord_ava_documentinternalid') + '&rectype=' + NetDocType + '&subid=' + recordObjArray[j].getValue('custrecord_ava_subsidiaryid');1200 1201 var FinalURL = '<a href="' + URL1 + '" target="_blank">' + recordObjArray[j].getValue('custrecord_ava_documentno') + '</a>';1202 1203 AVA_TransactionList.setLineItemValue('custrecord_ava_documentno', i+1, FinalURL);1204 }1205 else1206 {1207 AVA_TransactionList.setLineItemValue('custrecord_ava_documentno', i+1, recordObjArray[j].getValue('custrecord_ava_documentno'));1208 }1209 1210 AVA_TransactionList.setLineItemValue('custrecord_ava_netsuitedoctype', i+1, NetDocType);1211 AVA_TransactionList.setLineItemValue('custrecord_ava_totalamount', i+1, parseFloat(recordObjArray[j].getValue('custrecord_ava_totalamount')));1212 AVA_TransactionList.setLineItemValue('custrecord_ava_totaldiscount', i+1, parseFloat(recordObjArray[j].getValue('custrecord_ava_totaldiscount')));1213 AVA_TransactionList.setLineItemValue('custrecord_ava_totalnontaxable', i+1, parseFloat(recordObjArray[j].getValue('custrecord_ava_totalnontaxable')));1214 AVA_TransactionList.setLineItemValue('custrecord_ava_totaltaxable', i+1, parseFloat(recordObjArray[j].getValue('custrecord_ava_totaltaxable')));1215 AVA_TransactionList.setLineItemValue('custrecord_ava_totaltax', i+1, parseFloat(recordObjArray[j].getValue('custrecord_ava_totaltax')));1216 1217 }1218 1219 AVA_LineCount = i;1220 1221 if(AVA_Flag == 'F')1222 {1223 RecordCountStart = ListStart;1224 var RecordEnd = parseFloat(i) + parseFloat(ListStart);1225 RecordCountText = 'Records: ' + ((i==0) ? 1 : (parseFloat((RecordCountStart>=0)? RecordCountStart:0) + parseFloat(1))) + ' - ' + RecordEnd;1226 }1227 else1228 {1229 if(request.getMethod() == 'POST')1230 {1231 RecordCountStart = 0;1232 }1233 else1234 {1235 RecordCountStart = (request.getParameter('ava_liststart') == null)? 0:parseFloat(request.getParameter('ava_liststart'));1236 }1237 RecordCountText = 'Records: ' + ((i==0) ? 0 : (parseFloat(RecordCountStart) + parseFloat(1))) + ' - ' + j;1238 }1239 1240 if(RecordCountStart>0)1241 {1242 AVA_PrevFlag = 'T'; 1243 }1244 1245 if(i==ListLimit)1246 {1247 AVA_NextFlag = 'T';1248 }1249 1250 try1251 {1252 AVA_EndPage = String(parseFloat(recordObjArray.length)/parseFloat(ListLimit));1253 var AmountSplit = new Array();1254 AmountSplit = AVA_EndPage.split('.');1255 AVA_EndPage = parseFloat(AmountSplit[0]) * parseFloat(ListLimit);1256 }1257 catch(err)1258 {1259 }1260 RecordCountText = RecordCountText + ' of ' + recordObjArray.length;1261 AVA_TransactionList.setHelpText(RecordCountText);1262 1263 return j;1264}126512661267function AVA_ViewTransactions(request, response)1268{1269 if(AVA_CheckService('TaxSvc') == 0 && AVA_CheckSecurity( 12 ) == 0)1270 {1271 if(request.getMethod() == 'GET' || request.getMethod() == 'POST')1272 {1273 var AVA_TransactionForm = nlapiCreateForm('AvaTax Transactions');1274 AVA_TransactionForm.setScript('customscript_avatransactionlist_client');1275 AVA_TransactionForm.setTitle('AvaTax Transactions');1276 1277 var DateFrom = AVA_TransactionForm.addField('ava_datefrom', 'date', 'Starting Date');1278 DateFrom.setDefaultValue(request.getParameter('ava_datefrom'));1279 DateFrom.setMandatory(true);1280 1281 var DateTo = AVA_TransactionForm.addField('ava_dateto', 'date', 'Ending Date');1282 DateTo.setDefaultValue(request.getParameter('ava_dateto'));1283 DateTo.setMandatory(true);1284 1285 var DateFormat = AVA_TransactionForm.addField('ava_dateformat', 'text', 'Date Format');1286 DateFormat.setDefaultValue(nlapiGetContext().getSetting('PREFERENCE', 'DATEFORMAT'));1287 DateFormat.setMandatory(true);1288 DateFormat.setDisplayType('hidden');1289 1290 var DocumentType = AVA_TransactionForm.addField('ava_doctype', 'select', 'Document Type');1291 DocumentType.addSelectOption('1', 'All');1292 DocumentType.addSelectOption('2', 'SalesInvoice');1293 DocumentType.addSelectOption('6', 'ReturnInvoice');1294 DocumentType.setDefaultValue(request.getParameter('ava_doctype'));1295 DocumentType.setMandatory(true);1296 1297 var DocumentStatus = AVA_TransactionForm.addField('ava_docstatus', 'select', 'Document Status');1298 DocumentStatus.addSelectOption('1', 'All');1299// DocumentStatus.addSelectOption('2', 'Saved');1300 DocumentStatus.addSelectOption('3', 'Committed');1301 DocumentStatus.addSelectOption('4', 'Voided');1302 DocumentStatus.setDefaultValue(request.getParameter('ava_docstatus'));1303 DocumentStatus.setMandatory(true);1304 1305 var AVA_Tab = AVA_TransactionForm.addTab('custpage_avatab', '');1306 1307 var AVA_TransactionList = AVA_TransactionForm.addSubList('custpage_avatranslist', 'list', 'AvaTax Transactions', AVA_Tab); 1308 AVA_TransactionList.addField('avainternalid', 'text', 'Internal Id', null);1309 AVA_TransactionList.addField('avadocdate', 'date', 'Document Date', null);1310// AVA_TransactionList.addField('avatransid', 'text', 'AvaTax Transaction Id', null);1311 AVA_TransactionList.addField('avadocno', 'text', 'AvaTax Document Number', null);1312 AVA_TransactionList.addField('avanetdocno', 'text', 'NetSuite Document Number', null);1313 AVA_TransactionList.addField('avadoctype', 'text', 'AvaTax Document Type', null);1314 AVA_TransactionList.addField('avadocstatus', 'text', 'AvaTax Document Status', null);1315 AVA_TransactionList.addField('avataxdate', 'date', 'Tax Calculation Date', null);1316 AVA_TransactionList.addField('avatotamt', 'currency', 'Total Amount', null);1317 AVA_TransactionList.addField('avatotdisc', 'currency', 'Total Discount', null);1318 AVA_TransactionList.addField('avatotnontax', 'currency', 'Total Non-Taxable', null);1319 AVA_TransactionList.addField('avatottaxable', 'currency', 'Total Taxable', null);1320 AVA_TransactionList.addField('avatottax', 'currency', 'Total Tax', null);1321 AVA_TransactionList.getField('avainternalid').setDisplayType('hidden');1322 1323 if((request.getParameter('ava_datefrom') != null) && (request.getParameter('ava_datefrom').length > 0))1324 {1325 1326 //AVA_NextFlag = 'T';1327 var ListStart = AVA_GetTransactionData(request.getParameter('ava_datefrom'), request.getParameter('ava_dateto'), request.getParameter('ava_doctype'), request.getParameter('ava_docstatus'), AVA_TransactionList);1328 1329 AVA_TransactionForm.addField('ava_linecount','integer','Line Count').setDisplayType('hidden');1330 AVA_TransactionForm.getField('ava_linecount').setDefaultValue(AVA_LineCount);1331 1332 var FirstLink = '<<First Page';1333 var PrevLink = 'Previous';1334 var NextLink = 'Next';1335 var LastLink = 'Last Page>>';1336 1337 //First Page1338 if(AVA_PrevFlag == 'T')1339 {1340 var URL1 = nlapiResolveURL('SUITELET', 'customscript_avatransactionlist_suitelet', 'customdeploy_avatransactionlist', false);1341 URL1 = URL1 + '&ava_datefrom=' + request.getParameter('ava_datefrom') + '&ava_dateto=' + request.getParameter('ava_dateto') + '&ava_doctype='+request.getParameter('ava_doctype')+'&ava_docstatus='+request.getParameter('ava_docstatus');1342 URL1 = URL1 + '&ava_liststart=0';1343 1344 FirstLink = '<b><a href="'+ URL1 +'">\t\t\t\t<<First Page</a></b>';//>1345 } 1346 1347 //Previous1348 if(AVA_PrevFlag == 'T')1349 {1350 var URL1 = nlapiResolveURL('SUITELET', 'customscript_avatransactionlist_suitelet', 'customdeploy_avatransactionlist', false);1351 URL1 = URL1 + '&ava_liststart='+ ListStart + '&ava_flag=F' + '&ava_linecount=' + AVA_LineCount;1352 URL1 = URL1 + '&ava_datefrom=' + request.getParameter('ava_datefrom') + '&ava_dateto=' + request.getParameter('ava_dateto') + '&ava_doctype='+request.getParameter('ava_doctype')+'&ava_docstatus='+request.getParameter('ava_docstatus');1353 1354 PrevLink = '<b> <a href="'+ URL1 +'">Previous</a></b>';1355 }1356 1357 //Next1358 if(AVA_NextFlag == 'T')1359 {1360 URL1 = nlapiResolveURL('SUITELET', 'customscript_avatransactionlist_suitelet', 'customdeploy_avatransactionlist', false);1361 URL1 = URL1 + '&ava_liststart=' + ListStart + '&ava_flag=T' + '&ava_linecount=' + AVA_LineCount;1362 URL1 = URL1 + '&ava_datefrom=' + request.getParameter('ava_datefrom') + '&ava_dateto=' + request.getParameter('ava_dateto') + '&ava_doctype='+request.getParameter('ava_doctype')+'&ava_docstatus='+request.getParameter('ava_docstatus');1363 1364 NextLink = '<b> <a href="'+ URL1 +'">Next</a></b>';1365 }1366 1367 //Last Page1368 if(AVA_NextFlag == 'T')1369 {1370 URL1 = nlapiResolveURL('SUITELET', 'customscript_avatransactionlist_suitelet', 'customdeploy_avatransactionlist', false);1371 URL1 = URL1 + '&ava_datefrom=' + request.getParameter('ava_datefrom') + '&ava_dateto=' + request.getParameter('ava_dateto') + '&ava_doctype='+request.getParameter('ava_doctype')+'&ava_docstatus='+request.getParameter('ava_docstatus');1372 URL1 = URL1 + '&ava_liststart=' + AVA_EndPage + '&ava_linecount=' + AVA_LineCount;1373 1374 LastLink = '<b> <a href="'+ URL1 +'">Last Page>></a></b>';1375 } 1376 1377 AVA_TransactionForm.addField('ava_star','help','<br>(*) indicates Transactions deleted from NetSuite<br><br>').setLayoutType('outsidebelow','startrow');1378 1379 var emptyCells = '<td></td><td></td><td></td><td></td><td></td><td></td><td></td>';1380 var html = '<table cellspacing="20" align="center"><tr>' + emptyCells + emptyCells +'<td><font size="1">' + FirstLink+ '</font></td><td><font size="1">| ' + PrevLink + '</font></td>';1381 html +='<td><font size="1">| ' + NextLink + ' |</font></td><td><font size="1">' + LastLink+ '</font></td></tr></table>';1382 var PagingHtml = AVA_TransactionForm.addField('ava_pagelinks', 'help', html, null, AVA_Tab);1383 PagingHtml.setLayoutType('outsidebelow','startrow');1384 }1385 1386 AVA_TransactionForm.addSubmitButton('Get Records');1387 AVA_TransactionForm.addPageLink('breadcrumb', 'AvaTax Transactions', nlapiResolveURL('SUITELET', 'customscript_avatransactionlist_suitelet', 'customdeploy_avatransactionlist'));1388 1389 response.writePage(AVA_TransactionForm);1390 }1391 }1392}13931394function AVA_GetTransactionData(StartDate, EndDate, DocType, DocStatus, AVA_TransactionList)1395{1396 recordIdArray = new Array();1397 recordObjArray= new Array();1398 var RecordCountStart, RecordCountText;1399 var filters = new Array();1400 1401 if(DocType == 1 && DocStatus == 1)1402 {1403 filters[0] = new nlobjSearchFilter('custrecord_ava_documentdate', null, 'within', StartDate, EndDate);1404 }1405 else if(DocType == 1 && DocStatus != 1)1406 {1407 filters[0] = new nlobjSearchFilter('custrecord_ava_documentdate', null, 'within', StartDate, EndDate);1408 if(DocStatus > 1)1409 {1410 DocStatus = (DocStatus == 2)? 1 : DocStatus;1411 filters[1] = new nlobjSearchFilter('custrecord_ava_documentstatus', null, 'equalto', DocStatus);1412 }1413 } 1414 else 1415 {1416 filters[0] = new nlobjSearchFilter('custrecord_ava_documentdate', null, 'within', StartDate, EndDate);1417 filters[1] = new nlobjSearchFilter('custrecord_ava_documenttype', null, 'equalto', DocType);1418 if(DocStatus > 1)1419 {1420 DocStatus = (DocStatus == 2)? 1 : DocStatus;1421 filters[2] = new nlobjSearchFilter('custrecord_ava_documentstatus', null, 'equalto', DocStatus);1422 }1423 }1424 1425 var cols = new Array();1426 cols[0] = new nlobjSearchColumn('custrecord_ava_documentid');1427 cols[1] = new nlobjSearchColumn('custrecord_ava_documentdate');1428 cols[2] = new nlobjSearchColumn('custrecord_ava_documentinternalid');1429 cols[3] = new nlobjSearchColumn('custrecord_ava_documentno');1430 cols[4] = new nlobjSearchColumn('custrecord_ava_documenttype');1431 cols[5] = new nlobjSearchColumn('custrecord_ava_documentstatus');1432 cols[6] = new nlobjSearchColumn('custrecord_ava_taxcalculationdate');1433 cols[7] = new nlobjSearchColumn('custrecord_ava_totalamount');1434 cols[8] = new nlobjSearchColumn('custrecord_ava_totaldiscount');1435 cols[9] = new nlobjSearchColumn('custrecord_ava_totalnontaxable');1436 cols[10] = new nlobjSearchColumn('custrecord_ava_totaltaxable');1437 cols[11] = new nlobjSearchColumn('custrecord_ava_totaltax');1438 cols[12] = new nlobjSearchColumn('custrecord_ava_basecurrency');1439 cols[13] = new nlobjSearchColumn('custrecord_ava_foreigncurr');1440 cols[14] = new nlobjSearchColumn('custrecord_ava_exchangerate');14411442 var NetSuiteURL = 'http://system.netsuite.com';1443 var searchresult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);1444 1445 for( ; searchresult != null; )1446 {1447 for(var k=0; searchresult != null && k<searchresult.length; k++)1448 {1449 try1450 {1451 recordIdArray[recordIdArray.length] = searchresult[k].getId();1452 recordObjArray[recordObjArray.length] = searchresult[k];1453 }1454 catch(err)1455 {1456 }1457 }1458 1459 filters[filters.length] = new nlobjSearchFilter('internalid', null, 'noneof', recordIdArray);1460 1461 searchresult = nlapiSearchRecord('customrecord_avataxheaderdetails', null, filters, cols);1462 }1463 1464 if(request.getMethod() == 'POST')1465 {1466 var j = 0;1467 AVA_LineCount = 0;1468 }1469 else1470 {1471 var j = parseFloat(request.getParameter('ava_liststart'));1472 AVA_LineCount = parseFloat(request.getParameter('ava_linecount'));1473 }1474 1475 var ListLimit = parseFloat(nlapiGetContext().getSetting('PREFERENCE', 'LISTSEGMENTSIZE'));1476 var AVA_Flag = request.getParameter('ava_flag');1477 1478 if(AVA_Flag == 'F')1479 {1480 if(request.getParameter('ava_linecount')>0)1481 {1482 if(request.getParameter('ava_linecount')<ListLimit)1483 {1484 MaxLength = parseFloat(ListLimit) + parseFloat(AVA_LineCount);1485 ListStart = j = parseFloat(j) - parseFloat(MaxLength);1486 }1487 else1488 {1489 MaxLength = (parseFloat(ListLimit) * parseFloat(2));1490 ListStart = j = parseFloat(j) - parseFloat(MaxLength);1491 }1492 }1493 }1494 1495 for(var i=0; recordObjArray != null && i < ListLimit && j<recordObjArray.length && j>=0 ; j++)1496 {1497 1498 AVA_TransactionList.setLineItemValue('avainternalid', i+1, recordObjArray[j].getId());1499 AVA_TransactionList.setLineItemValue('avadocdate', i+1, recordObjArray[j].getValue('custrecord_ava_documentdate'));1500 1501 var DocType = recordObjArray[j].getValue('custrecord_ava_documenttype');1502 DocType = (DocType == 2)? 'SalesInvoice' : 'ReturnInvoice';1503 AVA_TransactionList.setLineItemValue('avadoctype', i+1, DocType);1504 1505 if(recordObjArray[j].getValue('custrecord_ava_documentinternalid') != null && recordObjArray[j].getValue('custrecord_ava_documentinternalid').length > 0)1506 {1507 var URL1 = nlapiResolveURL('SUITELET', 'customscript_avagettaxhistory_suitelet', 'customdeploy_gettaxhistory', false);1508 URL1 = URL1 + '&doctype=' + DocType +'&doccode=' + recordObjArray[j].getValue('custrecord_ava_documentinternalid') + '&subid='+ recordObjArray[j].getValue('custrecord_ava_subsidiaryid');1509 var FinalURL = '<a href="' + URL1 + '" target="_blank">' + recordObjArray[j].getValue('custrecord_ava_documentno') + '</a>';1510 1511 AVA_TransactionList.setLineItemValue('avanetdocno', i+1, FinalURL);1512 }1513 else1514 {1515 AVA_TransactionList.setLineItemValue('avanetdocno', i+1, recordObjArray[j].getValue('custrecord_ava_documentno'));1516 }1517 1518 var DocStatus = recordObjArray[j].getValue('custrecord_ava_documentstatus');1519 switch(DocStatus)1520 {1521 case '1':1522 DocStatus = 'Saved';1523 break;1524 1525 case '3':1526 DocStatus = 'Committed';1527 break;1528 1529 case '4':1530 DocStatus = 'Voided';1531 break;1532 1533 default:1534 DocStatus = '0';1535 break;1536 } 1537 AVA_TransactionList.setLineItemValue('avadocstatus', i+1, DocStatus);15381539 if(recordObjArray[j].getValue('custrecord_ava_documentinternalid') != null)1540 {1541 AVA_TransactionList.setLineItemValue('avadocno', i+1, recordObjArray[j].getValue('custrecord_ava_documentinternalid'));1542 }1543 else1544 {1545 AVA_TransactionList.setLineItemValue('avadocno', i+1, '*');1546 }1547 1548 AVA_TransactionList.setLineItemValue('avataxdate', i+1, recordObjArray[j].getValue('custrecord_ava_taxcalculationdate'));1549 AVA_TransactionList.setLineItemValue('avatotamt', i+1, parseFloat(recordObjArray[j].getValue('custrecord_ava_totalamount')));1550 AVA_TransactionList.setLineItemValue('avatotdisc', i+1, parseFloat(recordObjArray[j].getValue('custrecord_ava_totaldiscount')));1551 AVA_TransactionList.setLineItemValue('avatotnontax', i+1, parseFloat(recordObjArray[j].getValue('custrecord_ava_totalnontaxable')));1552 AVA_TransactionList.setLineItemValue('avatottaxable', i+1, parseFloat(recordObjArray[j].getValue('custrecord_ava_totaltaxable')));1553 AVA_TransactionList.setLineItemValue('avatottax', i+1, parseFloat(recordObjArray[j].getValue('custrecord_ava_totaltax')));1554 i++;1555 1556 }1557 1558 AVA_LineCount = i;1559 1560 1561 if(AVA_Flag == 'F')1562 {1563 RecordCountStart = ListStart;1564 var RecordEnd = parseFloat(i) + parseFloat(ListStart);1565 RecordCountText = 'Records: ' + ((i==0) ? 1 : (parseFloat((RecordCountStart>=0)? RecordCountStart:0) + parseFloat(1))) + ' - ' + RecordEnd;1566 }1567 else1568 {1569 if(request.getMethod() == 'POST')1570 {1571 RecordCountStart = 0;1572 }1573 else1574 {1575 RecordCountStart = parseFloat(request.getParameter('ava_liststart'));1576 }1577 RecordCountText = 'Records: ' + ((i==0) ? 0 : (parseFloat(RecordCountStart) + parseFloat(1))) + ' - ' + j;1578 }1579 1580 if(RecordCountStart>0)1581 {1582 AVA_PrevFlag = 'T'; 1583 }1584 1585 if(i==ListLimit)1586 {1587 AVA_NextFlag = 'T';1588 }1589 1590 try1591 {1592 AVA_EndPage = String(parseFloat(recordObjArray.length)/parseFloat(ListLimit));1593 var AmountSplit = new Array();1594 AmountSplit = AVA_EndPage.split('.');1595 AVA_EndPage = parseFloat(AmountSplit[0]) * parseFloat(ListLimit);1596 }1597 catch(err)1598 {1599 }1600 RecordCountText = RecordCountText + ' of ' + recordObjArray.length;1601 AVA_TransactionList.setHelpText(RecordCountText);1602 1603 return j;1604}16051606function AVA_ValidateDates()1607{1608 var StartDate = nlapiGetFieldValue('ava_datefrom');1609 var EndDate = nlapiGetFieldValue('ava_dateto');1610 var DateFormat = nlapiGetFieldValue('ava_dateformat');16111612 if(StartDate.length == 0)1613 {1614 alert('Select Starting Date');1615 return false;1616 }1617 1618 if(EndDate.length == 0)1619 {1620 alert('Select Ending Date');1621 return false;1622 }1623 1624 StartDate = new Date(AVA_FormatDate(DateFormat,StartDate));1625 EndDate = new Date(AVA_FormatDate(DateFormat,EndDate));1626 1627 if(EndDate < StartDate)1628 {1629 alert('Ending Date should be greater than or equal to Start Date');1630 return false;1631 }1632 1633 return true;1634}
...
AVA_CertFunctions.js
Source:AVA_CertFunctions.js
1/******************************************************************************************************2 Script Name - AVA_CertFunctions.js3 Company - Avalara Technologies Pvt Ltd.4******************************************************************************************************/56function AVA_CreateCustomerAvaCert()7{8 var config = nlapiGetFieldValue('custpage_ava_readconfig') == null ? AVA_ReadConfig('1') : AVA_LoadValuesFromField(); 9 if (AVA_CustomerCode != null && AVA_CustomerCode > 7)10 {11 alert("Customer cannot be created. " + AVA_ErrorCodeDesc(24));12 return;13 }14 15 var CustomerCode = AVA_GetCustomerInfo();16 var response ;17 var security = AVA_TaxSecurity(AVA_AccountValue, AVA_LicenseKey);18 var headers = AVA_Header(security);19 var body = AVA_CreateCustomerAvaCertBody(CustomerCode);20 var soapPayload = AVA_BuildEnvelope(headers + body);21 22 var soapHead = new Array();23 soapHead['Content-Type'] = 'text/xml';24 soapHead['SOAPAction'] = '"http://avatax.avalara.com/services/CustomerSave"';25 26 try27 { 28 response = nlapiRequestURL(AVA_ServiceUrl + '/avacert2/avacert2svc.asmx', soapPayload, soapHead);29 30 if(response.getCode() == 200)31 {32 var soapText = response.getBody();33 var soapXML = nlapiStringToXML(soapText);34 35 var CustomerSaveResult = nlapiSelectNode(soapXML, "//*[name()='CustomerSaveResult']");36 var ResultCode = nlapiSelectValue(CustomerSaveResult, "//*[name()='ResultCode']");37 38 if(ResultCode == 'Success')39 { 40 alert('The Customer record has been successfully created in AvaCert.'); 41 }42 else43 {44 alert(nlapiSelectValue( CustomerSaveResult, "//*[name()='Summary']") + '.. ' + nlapiSelectValue( CustomerSaveResult, "//*[name()='Details']"));45 }46 }47 else48 { 49 alert("AvaCert call failed. Please contact the Administrator." + response.getCode()); 50 } 51 }52 catch(err)53 {54 alert('Adding Customer on AvaCert was not successful.');55 }56 57}5859function AVA_CreateCustomerAvaCertBody(CustomerCode)60{61 var soap = null;62 soap = '\t<soap:Body>\n';63 soap += '\t\t<CustomerSave xmlns="http://avatax.avalara.com/services">\n';64 soap += '\t\t\t<CustomerSaveRequest>\n';65 soap += '\t\t\t\t<CompanyCode><![CDATA[' + nlapiGetContext().getCompany() + ']]></CompanyCode>\n';66 soap += '\t\t\t\t\t<Customer>\n';67 68 var phoneNumber = ((nlapiGetCurrentLineItemValue('addressbook','phone') != null && nlapiGetCurrentLineItemValue('addressbook','phone').length > 0) ? nlapiGetCurrentLineItemValue('addressbook','phone') : nlapiGetFieldValue('phone'));69 phoneNumber = phoneNumber.replace(/\(|\)/gi, ""); 70 71 var faxNumber = nlapiGetFieldValue('fax');72 faxNumber = faxNumber.replace(/\(|\)/gi, "");73 74 var email = ((nlapiGetCurrentLineItemValue('addressbook','custpage_ava_email') != null && nlapiGetCurrentLineItemValue('addressbook','custpage_ava_email').length > 0) ? nlapiGetCurrentLineItemValue('addressbook','custpage_ava_email') : nlapiGetFieldValue('email'));75 76 soap += '\t\t\t\t\t\t<CustomerCode><![CDATA[' + CustomerCode[0].substring(0,49) + ']]></CustomerCode>\n';77 soap += '\t\t\t\t\t\t<BusinessName><![CDATA[' + CustomerCode[1].substring(0,49) + ']]></BusinessName>\n';78 soap += '\t\t\t\t\t\t<Attn><![CDATA[' + nlapiGetCurrentLineItemValue('addressbook','attention') + ']]></Attn>\n';79 soap += '\t\t\t\t\t\t<Address1><![CDATA[' + nlapiGetCurrentLineItemValue('addressbook','addr1') + ']]></Address1>\n';80 soap += '\t\t\t\t\t\t<Address2><![CDATA[' + nlapiGetCurrentLineItemValue('addressbook','addr2') + ']]></Address2>\n';81 soap += '\t\t\t\t\t\t<City><![CDATA[' + nlapiGetCurrentLineItemValue('addressbook','city') + ']]></City>\n';82 soap += '\t\t\t\t\t\t<State><![CDATA[' + nlapiGetCurrentLineItemValue('addressbook','state') + ']]></State>\n';83 var ReturnCountryName = AVA_CheckCountryName(nlapiGetCurrentLineItemValue('addressbook','country'));84 soap += '\t\t\t\t\t\t<Country><![CDATA[' + ReturnCountryName[1] + ']]></Country>\n';85 soap += '\t\t\t\t\t\t<Zip><![CDATA[' + nlapiGetCurrentLineItemValue('addressbook','zip') + ']]></Zip>\n';86 soap += '\t\t\t\t\t\t<Phone><![CDATA[' + phoneNumber + ']]></Phone>\n';87 soap += '\t\t\t\t\t\t<Fax><![CDATA[' + faxNumber + ']]></Fax>\n';88 soap += '\t\t\t\t\t\t<Email><![CDATA[' + email + ']]></Email>\n';89 soap += '\t\t\t\t\t</Customer>\n';90 soap += '\t\t\t</CustomerSaveRequest>\n';91 soap += '\t\t</CustomerSave>\n';92 soap += '\t</soap:Body>\n';93 94 return soap;95}96 97function AVA_InitiateExemptCert()98{99 if(nlapiGetCurrentLineItemValue('addressbook','custpage_ava_communicationmode') == null || nlapiGetCurrentLineItemValue('addressbook','custpage_ava_communicationmode') == 0)100 {101 alert('The Exemption Certificate Workflow Request cannot be initiated because Communication mode is missing');102 return;103 }104 /*if(nlapiGetCurrentLineItemValue('addressbook','custpage_ava_communicationmode') == 'FAX' && (nlapiGetFieldValue('fax') == null || nlapiGetFieldValue('fax').length <= 0))105 {106 alert('The Exemption Certificate Workflow Request cannot be initiated because Fax information is missing.');107 return;108 }109 110 if(nlapiGetCurrentLineItemValue('addressbook','custpage_ava_communicationmode') == 'EMAIL' && (nlapiGetCurrentLineItemValue('addressbook','custpage_ava_email') == null || nlapiGetCurrentLineItemValue('addressbook','custpage_ava_email').length <= 0))111 {112 if(nlapiGetFieldValue('email') == null || nlapiGetFieldValue('email').length <= 0)113 {114 alert('The Exemption Certificate Workflow Request cannot be initiated because Email information is missing.');115 return;116 }117 }118 119 if(nlapiGetCurrentLineItemValue('addressbook','custpage_ava_custommessage') == null || (nlapiGetCurrentLineItemValue('addressbook','custpage_ava_custommessage') != null && nlapiGetCurrentLineItemValue('addressbook','custpage_ava_custommessage').length <= 0))120 {121 alert('The Exemption Certificate Workflow Request cannot be initiated because Custom Message is missing.');122 return;123 }*/124 125 var config = nlapiGetFieldValue('custpage_ava_readconfig') == null ? AVA_ReadConfig('1') : AVA_LoadValuesFromField(); 126 if (AVA_CustomerCode != null && AVA_CustomerCode > 7)127 {128 alert("The Exemption Certificate Workflow Request cannot be initiated. " + AVA_ErrorCodeDesc(24));129 return;130 }131132 var CustomerCode = AVA_GetCustomerInfo();133 var response ;134 var security = AVA_TaxSecurity(AVA_AccountValue, AVA_LicenseKey);135 var headers = AVA_Header(security);136 var body = AVA_InitiateExemptCertBody(CustomerCode);137 var soapPayload = AVA_BuildEnvelope(headers + body);138 139 var soapHead = new Array();140 soapHead['Content-Type'] = 'text/xml';141 soapHead['SOAPAction'] = '"http://avatax.avalara.com/services/CertificateRequestInitiate"';142 143 try144 { 145 response = nlapiRequestURL(AVA_ServiceUrl + '/avacert2/avacert2svc.asmx', soapPayload, soapHead);146 147 if(response.getCode() == 200)148 {149 var soapText = response.getBody();150 var soapXML = nlapiStringToXML(soapText);151152 var CertificateRequestInitiateResult = nlapiSelectNode(soapXML, "//*[name()='CertificateRequestInitiateResult']");153 var ResultCode = nlapiSelectValue(CertificateRequestInitiateResult, "//*[name()='ResultCode']");154 155 if(ResultCode == 'Success')156 { 157 var TrackingCode = nlapiSelectValue(CertificateRequestInitiateResult, "//*[name()='TrackingCode']");158 alert('The Exemption Certificate Workflow Request has been successfully generated. Tracking Code is � ' + TrackingCode); 159 }160 else161 {162 alert(nlapiSelectValue( CertificateRequestInitiateResult, "//*[name()='Summary']") + '.. ' + nlapiSelectValue( CertificateRequestInitiateResult, "//*[name()='Details']"));163 }164 } 165 else166 { 167 alert("AvaCert call failed. Please contact the Administrator."); 168 }169 }170 catch(err)171 {172 alert('Initiating Exemption Certificate on AvaCert was not successful.');173 }174}175176function AVA_InitiateExemptCertBody(CustomerCode)177{178 var soap = null;179 soap = '\t<soap:Body>\n';180 soap += '\t\t<CertificateRequestInitiate xmlns="http://avatax.avalara.com/services">\n';181 soap += '\t\t\t<CertificateRequestInitiateRequest>\n';182 soap += '\t\t\t\t<CompanyCode><![CDATA[' + nlapiGetContext().getCompany() + ']]></CompanyCode>\n';183 soap += '\t\t\t\t<CustomerCode><![CDATA[' + CustomerCode[0] + ']]></CustomerCode>\n';184 soap += '\t\t\t\t<CommunicationMode><![CDATA[' + nlapiGetCurrentLineItemValue('addressbook','custpage_ava_communicationmode') + ']]></CommunicationMode>\n';185 soap += '\t\t\t\t<CustomMessage><![CDATA[' + nlapiGetCurrentLineItemValue('addressbook','custpage_ava_custommessage') + ']]></CustomMessage>\n'; 186 soap += '\t\t\t</CertificateRequestInitiateRequest>\n';187 soap += '\t\t</CertificateRequestInitiate>\n';188 soap += '\t</soap:Body>\n';189 190 return soap;191}192 193function AVA_GetCustomerInfo()194{195 var webstoreFlag = (nlapiGetFieldValue('custpage_ava_context') == 'webstore') ? true : false;196 var CustomerCode = new Array(); // 0-Customer/Partner ID, 1-Customer/Partner Name197 switch(AVA_CustomerCode)198 {199 case '0':200 case '6':201 CustomerCode[0] = nlapiGetFieldValue('entityid');202 CustomerCode[1] = (nlapiGetFieldValue('isperson') == 'T') ? (nlapiGetFieldValue('firstname') + ((nlapiGetFieldValue('middlename') != null && nlapiGetFieldValue('middlename').length > 0)? ( ' ' + nlapiGetFieldValue('middlename') + ' ' ) : ' ') + nlapiGetFieldValue('lastname')) : (nlapiGetFieldValue('companyname'));203 break;204 205 case '1':206 var CustomerName = (nlapiGetFieldValue('isperson') == 'T') ? (nlapiGetFieldValue('firstname') + ((nlapiGetFieldValue('middlename') != null && nlapiGetFieldValue('middlename').length > 0)? ( ' ' + nlapiGetFieldValue('middlename') + ' ' ) : ' ') + nlapiGetFieldValue('lastname')) : (nlapiGetFieldValue('companyname'));207 CustomerCode[0] = CustomerName;208 CustomerCode[1] = CustomerName;209 break;210211 case '2':212 var CustomerName = (nlapiGetFieldValue('isperson') == 'T') ? (nlapiGetFieldValue('firstname') + ((nlapiGetFieldValue('middlename') != null && nlapiGetFieldValue('middlename').length > 0)? ( ' ' + nlapiGetFieldValue('middlename') + ' ' ) : ' ') + nlapiGetFieldValue('lastname')) : (nlapiGetFieldValue('companyname'));213 CustomerCode[0] = nlapiGetRecordId();214 CustomerCode[1] = CustomerName;215 break;216217 case '3':218 case '7':219 if(nlapiGetRecordType() == 'partner')220 {221 var PartnerName = (nlapiGetFieldValue('isperson') == 'T') ? (nlapiGetFieldValue('firstname') + ((nlapiGetFieldValue('middlename') != null && nlapiGetFieldValue('middlename').length > 0)? ( ' ' + nlapiGetFieldValue('middlename') + ' ' ) : ' ') + nlapiGetFieldValue('lastname')) : (nlapiGetFieldValue('companyname'));222 CustomerCode[0] = nlapiGetFieldValue('entityid');223 CustomerCode[1] = PartnerName;224 }225 else226 {227 if (nlapiGetContext().getFeature('multipartner') != true && nlapiGetFieldValue('partner') != null && nlapiGetFieldValue('partner').length > 0)228 {229 var response = nlapiRequestURL(nlapiResolveURL('SUITELET', 'customscript_ava_recordload_suitelet', 'customdeploy_ava_recordload', webstoreFlag) + '&type=partner&id=' + nlapiGetFieldValue('partner'), null, null );230 var fieldValues = response.getBody().split('+');231 CustomerCode[0] = fieldValues[5];232 CustomerCode[1] = (fieldValues[0] == true) ? (fieldValues[1] + ((fieldValues[2] != null && fieldValues[2].length > 0)? ( ' ' + fieldValues[2] + ' ' ) : ' ') + fieldValues[3]) : (fieldValues[4]);233 234 }235 else236 {237 var CustomerName = (nlapiGetFieldValue('isperson') == 'T') ? (nlapiGetFieldValue('firstname') + ((nlapiGetFieldValue('middlename') != null && nlapiGetFieldValue('middlename').length > 0)? ( ' ' + nlapiGetFieldValue('middlename') + ' ' ) : ' ') + nlapiGetFieldValue('lastname')) : (nlapiGetFieldValue('companyname'));238 CustomerCode[0] = nlapiGetFieldValue('entityid');239 CustomerCode[1] = CustomerName;240 }241 }242 break;243244 case '4':245 if(nlapiGetRecordType() == 'partner')246 {247 var PartnerName = (nlapiGetFieldValue('isperson') == 'T') ? (nlapiGetFieldValue('firstname') + ((nlapiGetFieldValue('middlename') != null && nlapiGetFieldValue('middlename').length > 0)? ( ' ' + nlapiGetFieldValue('middlename') + ' ' ) : ' ') + nlapiGetFieldValue('lastname')) : (nlapiGetFieldValue('companyname'));248 CustomerCode[0] = PartnerName;249 CustomerCode[1] = PartnerName;250 }251 else252 {253 if (nlapiGetContext().getFeature('multipartner') != true && nlapiGetFieldValue('partner') != null && nlapiGetFieldValue('partner').length > 0)254 {255 var response = nlapiRequestURL(nlapiResolveURL('SUITELET', 'customscript_ava_recordload_suitelet', 'customdeploy_ava_recordload', webstoreFlag) + '&type=partner&id=' + nlapiGetFieldValue('partner'), null, null );256 var fieldValues = response.getBody().split('+');257 CustomerCode[0] = (fieldValues[0] == true) ? (fieldValues[1] + ((fieldValues[2] != null && fieldValues[2].length > 0)? ( ' ' + fieldValues[2] + ' ' ) : ' ') + fieldValues[3]) : (fieldValues[4]);258 CustomerCode[1] = (fieldValues[0] == true) ? (fieldValues[1] + ((fieldValues[2] != null && fieldValues[2].length > 0)? ( ' ' + fieldValues[2] + ' ' ) : ' ') + fieldValues[3]) : (fieldValues[4]);259 }260 else261 {262 var CustomerName = (nlapiGetFieldValue('isperson') == 'T') ? (nlapiGetFieldValue('firstname') + ((nlapiGetFieldValue('middlename') != null && nlapiGetFieldValue('middlename').length > 0)? ( ' ' + nlapiGetFieldValue('middlename') + ' ' ) : ' ') + nlapiGetFieldValue('lastname')) : (nlapiGetFieldValue('companyname'));263 CustomerCode[0] = CustomerName;264 CustomerCode[1] = CustomerName;265 }266 }267 break;268269 case '5':270 if(nlapiGetRecordType() == 'partner')271 {272 var PartnerName = (nlapiGetFieldValue('isperson') == 'T') ? (nlapiGetFieldValue('firstname') + ((nlapiGetFieldValue('middlename') != null && nlapiGetFieldValue('middlename').length > 0)? ( ' ' + nlapiGetFieldValue('middlename') + ' ' ) : ' ') + nlapiGetFieldValue('lastname')) : (nlapiGetFieldValue('companyname'));273 CustomerCode[0] = nlapiGetRecordId();274 CustomerCode[1] = PartnerName;275 }276 else277 {278 if (nlapiGetContext().getFeature('multipartner') != true && nlapiGetFieldValue('partner') != null && nlapiGetFieldValue('partner').length > 0)279 {280 var response = nlapiRequestURL(nlapiResolveURL('SUITELET', 'customscript_ava_recordload_suitelet', 'customdeploy_ava_recordload', webstoreFlag) + '&type=partner&id=' + nlapiGetFieldValue('partner'), null, null ); 281 var fieldValues = response.getBody().split('+');282 CustomerCode[0] = nlapiGetFieldValue('partner');283 CustomerCode[1] = (fieldValues[0] == true) ? (fieldValues[1] + ((fieldValues[2] != null && fieldValues[2].length > 0)? ( ' ' + fieldValues[2] + ' ' ) : ' ') + fieldValues[3]) : (fieldValues[4]);284 }285 else286 {287 var CustomerName = (nlapiGetFieldValue('isperson') == 'T') ? (nlapiGetFieldValue('firstname') + ((nlapiGetFieldValue('middlename') != null && nlapiGetFieldValue('middlename').length > 0)? ( ' ' + nlapiGetFieldValue('middlename') + ' ' ) : ' ') + nlapiGetFieldValue('lastname')) : (nlapiGetFieldValue('companyname'));288 CustomerCode[0] = nlapiGetRecordId();289 CustomerCode[1] = CustomerName;290 }291 }292 break;293 294 default:295 CustomerCode = 0;296 break;297 }298 return CustomerCode;299}300301function AVA_CertificatesForm(request, response)302{303 if(AVA_CheckService('AvaCert2Svc') == 0 && AVA_CheckSecurity( 26 ) == 0)304 {305 if(request.getMethod() == 'GET')306 {307 var AVA_CertificatesForm = nlapiCreateForm('Get Certificate(s)/Status');308 AVA_CertificatesForm.setTitle('Get Certificate(s)/Status');309 AVA_CertificatesForm.setScript('customscript_avacertificates_client');310 311 AVA_ReadConfig('0');312 313 AVA_CertificatesForm.addField('ava_customercode', 'text', 'Customer Code').setDisplayType('hidden');314 AVA_CertificatesForm.getField('ava_customercode').setDefaultValue(AVA_CustomerCode);315 316 AVA_CertificatesForm.addField('ava_customerid', 'text', 'Customer Id').setDisplayType('hidden');317 AVA_CertificatesForm.addField('ava_partnerid', 'text', 'Customer Id').setDisplayType('hidden');318 319 AVA_CertificatesForm.addField('ava_record', 'label', 'Record type').setLayoutType('startrow');320 AVA_CertificatesForm.addField('ava_recordtype', 'radio', 'Customer', 'customer').setLayoutType('midrow');321 if(nlapiGetContext().getFeature('prm') == true)322 {323 AVA_CertificatesForm.addField('ava_recordtype', 'radio', 'Partner', 'partner').setLayoutType('midrow');324 AVA_CertificatesForm.getField('ava_recordtype').setDefaultValue('customer');325 }326 else327 {328 AVA_CertificatesForm.getField('ava_recordtype').setDefaultValue('customer');329 AVA_CertificatesForm.getField('ava_record').setDisplayType('hidden');330 AVA_CertificatesForm.getField('ava_recordtype').setDisplayType('hidden');331 }332 333 AVA_CertificatesForm.addField('ava_customer', 'select', 'Customer', 'customer').setLayoutType('startrow');334 if(nlapiGetContext().getFeature('prm') == true)335 {336 AVA_CertificatesForm.addField('ava_partner', 'select', 'Partner', 'partner').setLayoutType('midrow');337 AVA_CertificatesForm.getField('ava_partner').setDisplayType('disabled');338 if(AVA_CustomerCode != null && (AVA_CustomerCode == 0 || AVA_CustomerCode == 1 || AVA_CustomerCode == 2 || AVA_CustomerCode == 6))339 {340 AVA_CertificatesForm.getField('ava_recordtype').setDisplayType('disabled');341 AVA_CertificatesForm.getField('ava_partner').setDisplayType('disabled');342 }343 }344 345 AVA_CertificatesForm.addButton('ava_getcertificate','Retrieve Certificate(s)', "AVA_GetCertificates_UI()");346 AVA_CertificatesForm.addButton('ava_getcertificatestatus','Retrieve Certificate(s) Status', "AVA_GetCertificatesStatus_UI()");347 response.writePage(AVA_CertificatesForm);348 }349 }350}351352function AVA_CertficatesChanges(type, name)353{354 if(name == 'ava_recordtype')355 {356 if(nlapiGetFieldValue('ava_recordtype') == 'partner')357 {358 nlapiDisableField('ava_customer', true);359 nlapiDisableField('ava_partner', false);360 }361 else362 {363364 nlapiDisableField('ava_partner', true);365 nlapiDisableField('ava_customer', false);366 }367 }368 if(name == 'ava_customer')369 {370 if(nlapiGetFieldValue('ava_customer') != null && nlapiGetFieldValue('ava_customer').length > 0)371 {372 var response = nlapiRequestURL(nlapiResolveURL('SUITELET', 'customscript_ava_recordload_suitelet', 'customdeploy_ava_recordload', false) + '&type=customer&id=' + nlapiGetFieldValue('ava_customer'), null, null );373 nlapiSetFieldValue('ava_customerid', JSON.stringify(response.getBody().split('+')));374 }375 else376 {377 nlapiSetFieldValue('ava_customerid', '');378 }379 }380 if(name == 'ava_partner')381 {382 if(nlapiGetFieldValue('ava_partner') != null && nlapiGetFieldValue('ava_partner').length > 0)383 {384 var response = nlapiRequestURL(nlapiResolveURL('SUITELET', 'customscript_ava_recordload_suitelet', 'customdeploy_ava_recordload', false) + '&type=partner&id=' + nlapiGetFieldValue('ava_partner'), null, null );385 nlapiSetFieldValue('ava_partnerid', JSON.stringify(response.getBody().split('+')));386 }387 else388 {389 nlapiSetFieldValue('ava_partnerid', '');390 }391 }392}393394function AVA_GetCertificates_UI()395{396 if (nlapiGetFieldValue('ava_customercode') != null && nlapiGetFieldValue('ava_customercode') > 7)397 {398 alert("Certificate(s) cannot be retrieved. " + AVA_ErrorCodeDesc(24));399 return;400 }401 402 AVA_RedirectToSuitelet('0');403}404405function AVA_GetCertificatesStatus_UI()406{407 if (nlapiGetFieldValue('ava_customercode') != null && nlapiGetFieldValue('ava_customercode') > 7)408 {409 alert("Certificate(s) status cannot be retrieved. " + AVA_ErrorCodeDesc(24));410 return;411 }412 413 AVA_RedirectToSuitelet('1');414}415416function AVA_RedirectToSuitelet(type) //type..... 0 - Certificates Suitelet, 1 - Certificates Status Suitelet417{418 var CustomerCode;419 420 if(nlapiGetFieldValue('ava_recordtype') == 'customer')421 {422 if(nlapiGetFieldValue('ava_customer') == null || nlapiGetFieldValue('ava_customer').length == 0)423 {424 alert('Please select Customer');425 return;426 }427 var customerid = JSON.parse(nlapiGetFieldValue('ava_customerid'));428 }429 else430 {431 if(nlapiGetFieldValue('ava_partner') == null || nlapiGetFieldValue('ava_partner').length == 0)432 {433 alert('Please select Partner');434 return;435 }436 var customerid = JSON.parse(nlapiGetFieldValue('ava_partnerid'));437 }438 439 switch(nlapiGetFieldValue('ava_customercode'))440 {441 case '0':442 case '6':443 CustomerCode = customerid[5];444 break;445 446 case '1':447 var CustomerName = (customerid[0] == 'T') ? (customerid[1] + ((customerid[2] != 'null' && customerid[2].length > 0)? ( ' ' + customerid[2] + ' ' ) : ' ') + customerid[3]) : (customerid[4]);448 CustomerCode = CustomerName;449 break;450 451 case '2':452 CustomerCode = nlapiGetFieldValue('ava_customer');453 break;454 455 case '3':456 case '7':457 if(nlapiGetFieldValue('ava_recordtype') == 'partner')458 {459 CustomerCode = customerid[5];460 }461 else462 {463 if (nlapiGetContext().getFeature('multipartner') != true && customerid[6] != 'null' && customerid[6].length > 0)464 {465 var response = nlapiRequestURL(nlapiResolveURL('SUITELET', 'customscript_ava_recordload_suitelet', 'customdeploy_ava_recordload', false) + '&type=partner&id=' + customerid[6], null, null );466 var fieldValues = response.getBody().split('+');467 CustomerCode = fieldValues[5];468 }469 else470 {471 CustomerCode = customerid[5];472 }473 }474 break;475 476 case '4':477 if(nlapiGetFieldValue('ava_recordtype') == 'partner')478 {479 var PartnerName = (customerid[0] == 'T') ? (customerid[1] + ((customerid[2] != 'null' && customerid[2].length > 0)? ( ' ' + customerid[2] + ' ' ) : ' ') + customerid[3]) : (customerid[4]);480 CustomerCode = PartnerName;481 }482 else483 {484 if (nlapiGetContext().getFeature('multipartner') != true && customerid[6] != 'null' && customerid[6].length > 0)485 {486 var response = nlapiRequestURL(nlapiResolveURL('SUITELET', 'customscript_ava_recordload_suitelet', 'customdeploy_ava_recordload', false) + '&type=partner&id=' + customerid[6], null, null );487 var fieldValues = response.getBody().split('+');488 CustomerCode = (fieldValues[0] == 'T') ? (fieldValues[1] + ((fieldValues[2] != 'null' && fieldValues[2].length > 0)? ( ' ' + fieldValues[2] + ' ' ) : ' ') + fieldValues[3]) : (fieldValues[4]);489 }490 else491 {492 var CustomerName = (customerid[0] == 'T') ? (customerid[1] + ((customerid[2] != 'null' && customerid[2].length > 0)? ( ' ' + customerid[2] + ' ' ) : ' ') + customerid[3]) : (customerid[4]);493 CustomerCode = CustomerName;494 }495 }496 break;497 498 case '5':499 if(nlapiGetFieldValue('ava_recordtype') == 'partner')500 {501 CustomerCode = nlapiGetFieldValue('ava_partner');502 }503 else504 {505 if (nlapiGetContext().getFeature('multipartner') != true && customerid[6] != 'null' && customerid[6].length > 0)506 {507 CustomerCode = customerid[6];508 }509 else510 {511 CustomerCode = nlapiGetFieldValue('ava_customer');512 }513 }514 break;515 516 default:517 CustomerCode = 0;518 break;519 }520 521 if(type == '0')522 {523 var URL = nlapiResolveURL('SUITELET', 'customscript_avagetcertificates_suitelet', 'customdeploy_avagetcertificates', false);524 }525 else526 {527 var URL = nlapiResolveURL('SUITELET', 'customscript_avacertstatus_suitelet', 'customdeploy_avacertstatus', false);528 }529 URL = URL + '&customercode=' + CustomerCode;530 window.open(URL, '_blank');531}532533function AVA_GetCertificates()534{535 var config = nlapiGetFieldValue('custpage_ava_readconfig') == null ? AVA_ReadConfig('1') : AVA_LoadValuesFromField();536 if (AVA_CustomerCode != null && AVA_CustomerCode > 7)537 {538 alert("Certificate(s) cannot be retrieved. " + AVA_ErrorCodeDesc(24));539 return;540 }541 542 var CustomerCode = AVA_GetCustomerInfo();543 var URL = nlapiResolveURL('SUITELET', 'customscript_avagetcertificates_suitelet', 'customdeploy_avagetcertificates', false);544 URL = URL + '&customercode=' + CustomerCode[0];545 window.open(URL, '_blank');546}547548function AVA_CertificatesStatus()549{550 var config = nlapiGetFieldValue('custpage_ava_readconfig') == null ? AVA_ReadConfig('1') : AVA_LoadValuesFromField();551 if (AVA_CustomerCode != null && AVA_CustomerCode > 7)552 {553 alert("Certificate(s) status cannot be retrieved. " + AVA_ErrorCodeDesc(24));554 return;555 }556 557 var CustomerCode = AVA_GetCustomerInfo();558 var URL = nlapiResolveURL('SUITELET', 'customscript_avacertstatus_suitelet', 'customdeploy_avacertstatus', false);559 URL = URL + '&customercode=' + CustomerCode[0];560 window.open(URL, '_blank');561}562563function AVA_GetCertificatesDetails(request, response)564{565 if(AVA_CheckService('AvaCert2Svc') == 0 && AVA_CheckSecurity( 24 ) == 0)566 {567 if(request.getMethod() == 'GET')568 {569 var AVA_GetCertificatesDetailsForm = nlapiCreateForm('Certificate(s) Details');570 AVA_GetCertificatesDetailsForm.setTitle('Certificate(s) Details');571 AVA_GetCertificatesDetailsForm.setScript('customscript_avaentity_client');572 573 AVA_ReadConfig('0');574 575 var security = AVA_TaxSecurity(AVA_AccountValue, AVA_LicenseKey);576 var headers = AVA_Header(security);577 var body = AVA_CertificateGetBody(request.getParameter('customercode'));578 var soapPayload = AVA_BuildEnvelope(headers + body);579 580 var soapHead = new Array();581 soapHead['Content-Type'] = 'text/xml';582 soapHead['SOAPAction'] = '"http://avatax.avalara.com/services/CertificateGet"';583 584 try585 {586 var AVA_CertificateListResponse = nlapiRequestURL(AVA_ServiceUrl + '/avacert2/avacert2svc.asmx', soapPayload, soapHead);587 if(AVA_CertificateListResponse.getCode() == 200)588 {589 var soapText = AVA_CertificateListResponse.getBody();590 var soapXML = nlapiStringToXML(soapText);591 var AVA_ResponseCertificateArray = new Array();592 593 var CertificateGetResult = nlapiSelectNode(soapXML, "//*[name()='CertificateGetResult']");594 var ResultCode = nlapiSelectValue(CertificateGetResult, "//*[name()='ResultCode']");595 596 if(ResultCode == 'Success')597 {598 AVA_GetCertificatesDetailsForm.addField('ava_customercode', 'text', 'Customer Code');599 AVA_GetCertificatesDetailsForm.getField('ava_customercode').setDefaultValue(request.getParameter('customercode'));600 AVA_GetCertificatesDetailsForm.getField('ava_customercode').setDisplayType('inline');601 602 AVA_GetCertificatesDetailsForm.addField('ava_folderid', 'text', 'Folder Id');603 AVA_GetCertificatesDetailsForm.getField('ava_folderid').setDisplayType('hidden');604 605 var AVA_FileFormat = AVA_GetCertificatesDetailsForm.addField('ava_fileformat', 'select', 'Select File Format');606 AVA_FileFormat.addSelectOption('PNG','PNG');607 AVA_FileFormat.addSelectOption('PDF','PDF');608 AVA_FileFormat.setDefaultValue('PNG');609 610 var AVA_CertificateList = AVA_GetCertificatesDetailsForm.addSubList('custpage_avacertlist', 'list','AvaTax Certificate(s) Details');611 612 AVA_CertificateList.addField('ava_getimage', 'radio', 'Get Image');613 AVA_CertificateList.addField('ava_certid','text', 'ACertID');614 AVA_CertificateList.addField('ava_jurisdiction','text', 'Jurisdiction');615 AVA_CertificateList.addField('ava_certstatus','text', 'Cert Status');616 AVA_CertificateList.addField('ava_reviewstatus','text', 'Review Status');617 AVA_CertificateList.addField('ava_address','text', 'Address');618 AVA_CertificateList.addField('ava_certusage','text', 'Certificate Usage');619 AVA_CertificateList.addField('ava_exemptformname','text', 'Exemption Form Name');620 AVA_CertificateList.addField('ava_exemptreasoncode','text', 'Exemption Reason Code');621 AVA_CertificateList.addField('ava_pagecount','text', 'Pages');622 AVA_CertificateList.addField('ava_page','text', 'Page Number');623 AVA_CertificateList.getField('ava_page').setDisplayType('entry');624 625 AVA_GetCertificatesDetailsForm.addButton('custpage_ava_getimage','Get Certificate', "AVA_GetCertImage()");626 627 var Certificates = nlapiSelectNode(CertificateGetResult, "//*[name()='Certificates']");628 AVA_ResponseCertificateArray = nlapiSelectNodes(Certificates, "./*[name()='Certificate']");629 630 var filter = new Array();631 filter[0] = new nlobjSearchFilter('name', null, 'is', 'AVA_ExemptionCertificate');632 633 var column = new Array();634 column[0] = new nlobjSearchColumn('internalid'); 635 636 var searchresult = nlapiSearchRecord('folder', null, filter, column);637 638 if(searchresult == null)639 {640 var filters = new Array();641 filters[0] = new nlobjSearchFilter('name', null, 'is', 'Bundle 1894');642 643 var columns = new Array();644 columns[0] = new nlobjSearchColumn('internalid'); 645 646 var searchresult1 = nlapiSearchRecord('folder', null, filters, columns);647 var folder = nlapiCreateRecord('folder');648 folder.setFieldValue('parent',searchresult1[0].getValue('internalid'));649 folder.setFieldValue('name','AVA_ExemptionCertificate');650 var FolderId = nlapiSubmitRecord(folder);651 }652 else653 {654 var FolderId = searchresult[0].getValue('internalid');655 }656 AVA_GetCertificatesDetailsForm.getField('ava_folderid').setDefaultValue(FolderId);657 658 for(var i=0; AVA_ResponseCertificateArray != null && i<AVA_ResponseCertificateArray.length ; i++)659 {660 var Jurisdications = '';661 662 AVA_CertificateList.setLineItemValue('ava_certid', i+1, nlapiSelectValue(AVA_ResponseCertificateArray[i] , "./*[name()='AvaCertId']"));663 664 var AVA_Jurisdiction = nlapiSelectNodes(nlapiSelectNode(AVA_ResponseCertificateArray[i], "./*[name()='CertificateJurisdictions']"), "./*[name()='CertificateJurisdiction']");665 for(var j = 0; AVA_Jurisdiction != null && j < AVA_Jurisdiction.length; j++)666 {667 Jurisdications += nlapiSelectValue(AVA_Jurisdiction[j], "./*[name()='Jurisdiction']");668 if(j != AVA_Jurisdiction.length - 1)669 {670 Jurisdications += ', ';671 }672 }673 AVA_CertificateList.setLineItemValue('ava_jurisdiction', i+1, Jurisdications);674 675 var Address1 = nlapiSelectValue(AVA_ResponseCertificateArray[i], "./*[name()='Address1']");676 var City = nlapiSelectValue(AVA_ResponseCertificateArray[i], "./*[name()='City']");677 var State = nlapiSelectValue(AVA_ResponseCertificateArray[i], "./*[name()='State']");678 var Zip = nlapiSelectValue(AVA_ResponseCertificateArray[i], "./*[name()='Zip']");679 var Country = nlapiSelectValue(AVA_ResponseCertificateArray[i], "./*[name()='Country']");680 681 var Address = Address1 +", "+ City +", "+ State +", "+ Zip +", " + Country;682 AVA_CertificateList.setLineItemValue('ava_address', i+1,Address);683 AVA_CertificateList.setLineItemValue('ava_certstatus', i+1, nlapiSelectValue(AVA_ResponseCertificateArray[i], "./*[name()='CertificateStatus']"));684 AVA_CertificateList.setLineItemValue('ava_reviewstatus', i+1, nlapiSelectValue(AVA_ResponseCertificateArray[i], "./*[name()='ReviewStatus']"));685 AVA_CertificateList.setLineItemValue('ava_certusage', i+1, nlapiSelectValue(AVA_ResponseCertificateArray[i], "./*[name()='CertificateUsage']"));686 AVA_CertificateList.setLineItemValue('ava_exemptformname', i+1, nlapiSelectValue(AVA_ResponseCertificateArray[i], "./*[name()='ExemptFormName']"));687 AVA_CertificateList.setLineItemValue('ava_exemptreasoncode', i+1, nlapiSelectValue(AVA_ResponseCertificateArray[i], "./*[name()='ExemptReasonCode']"));688 AVA_CertificateList.setLineItemValue('ava_pagecount', i+1, nlapiSelectValue(AVA_ResponseCertificateArray[i], "./*[name()='PageCount']"));689 }690 }691 else692 {693 var AVA_Messages = nlapiSelectNode( CertificateGetResult, "//*[name()='Messages']");694 var AVA_Message = nlapiSelectValue( AVA_Messages, "//*[name()='Summary']");695 nlapiLogExecution('DEBUG', 'Error Message', AVA_Message);696 nlapiLogExecution('DEBUG', 'Error', AVA_CertificateListResponse.getCode());697 }698 }699 else700 {701 nlapiLogExecution('DEBUG', 'Please contact the administrator');702 nlapiLogExecution('DEBUG', 'Response Code', AVA_CertificateListResponse.getCode());703 }704 response.writePage(AVA_GetCertificatesDetailsForm);705 }706 catch(err)707 {708 nlapiLogExecution('Debug', 'error', err.message);709 }710 }711 }712}713714function AVA_GetCertImage()715{716 var config = nlapiGetFieldValue('custpage_ava_readconfig') == null ? AVA_ReadConfig('1') : AVA_LoadValuesFromField();717 718 for(var i = 1; i <= nlapiGetLineItemCount('custpage_avacertlist'); i++)719 {720 if(nlapiGetLineItemValue('custpage_avacertlist', 'ava_getimage', i) == 'T')721 {722 if(nlapiGetFieldValue('ava_fileformat') == 'PNG' && nlapiGetLineItemValue('custpage_avacertlist','ava_page', i) != null && nlapiGetLineItemValue('custpage_avacertlist','ava_page', i).length > 0)723 {724 if(nlapiGetLineItemValue('custpage_avacertlist','ava_page', i) > nlapiGetLineItemValue('custpage_avacertlist','ava_pagecount', i))725 {726 alert('Invalid page number');727 return;728 }729 }730 731 var URL = nlapiResolveURL('SUITELET', 'customscript_avagetcertimage_suitelet', 'customdeploy_avagetcertificateimage', false);732 URL = URL + '&custparam_customercode=' + nlapiGetFieldValue('ava_customercode') + '&custparam_ava_certid=' + nlapiGetLineItemValue('custpage_avacertlist','ava_certid', i) + '&custparam_ava_folderid=' + nlapiGetFieldValue('ava_folderid') + '&custparam_ava_fileformat=' + nlapiGetFieldValue('ava_fileformat') + '&custparam_ava_page=' + nlapiGetLineItemValue('custpage_avacertlist','ava_page', i);733 window.open(URL, '_blank');734 }735 }736}737738function AVA_GetCertificateImage(request, response)739{740 if(AVA_CheckService('AvaCert2Svc') == 0 && AVA_CheckSecurity( 25 ) == 0)741 {742 if(request.getMethod() == 'GET')743 {744 var AVA_GetCertificatesImageForm = nlapiCreateForm('Exemption Certificate');745 AVA_GetCertificatesImageForm.setTitle('Exemption Certificate');746 747 AVA_ReadConfig('0');748 749 var security = AVA_TaxSecurity(AVA_AccountValue, AVA_LicenseKey);750 var headers = AVA_Header(security);751 var body = AVA_GetCertificateImageBody(request.getParameter('custparam_ava_certid'), request.getParameter('custparam_ava_fileformat'), request.getParameter('custparam_ava_page'));752 var soapPayload = AVA_BuildEnvelope(headers + body);753 754 var soapHead = new Array();755 soapHead['Content-Type'] = 'text/xml';756 soapHead['SOAPAction'] = '"http://avatax.avalara.com/services/CertificateImageGet"';757 758 try759 {760 var AVA_CertificateImageResponse = nlapiRequestURL(AVA_ServiceUrl + '/avacert2/avacert2svc.asmx', soapPayload, soapHead);761 if (AVA_CertificateImageResponse.getCode() == 200)762 {763 var soapText = AVA_CertificateImageResponse.getBody();764 var soapXML = nlapiStringToXML(soapText);765 766 var AVA_CertificateImageGetResult = nlapiSelectNode(soapXML, "//*[name()='CertificateImageGetResult']");767 AVA_ResultCode = nlapiSelectValue( AVA_CertificateImageGetResult, "//*[name()='ResultCode']");768 if (AVA_ResultCode == 'Success') 769 {770 AVA_GetCertificatesImageForm.addField('ava_customercode','text', 'Customer Code');771 AVA_GetCertificatesImageForm.getField('ava_customercode').setDefaultValue(request.getParameter('custparam_customercode'));772 AVA_GetCertificatesImageForm.getField('ava_customercode').setDisplayType('inline');773 774 AVA_GetCertificatesImageForm.addField('ava_certid','text', 'Cert ID');775 AVA_GetCertificatesImageForm.getField('ava_certid').setDefaultValue(request.getParameter('custparam_ava_certid'));776 AVA_GetCertificatesImageForm.getField('ava_certid').setDisplayType('inline');777 778 AVA_GetCertificatesImageForm.addTab('custpage_avaimagetab', 'Cert Image');779 780 var fileType = (request.getParameter('custparam_ava_fileformat') == 'PNG') ? 'PNGIMAGE' : 'PDF';781 var AVA_CertImage = nlapiSelectValue( AVA_CertificateImageGetResult, "//*[name()='Image']");782 783 if(request.getParameter('custparam_ava_fileformat') == 'PNG')784 {785 var html = '<img src="data:image/png;base64,' + AVA_CertImage + '" width="1000" height="1000"/>';786 }787 else788 {789 var file = nlapiCreateFile(request.getParameter('custparam_ava_certid') + '.' + request.getParameter('custparam_ava_fileformat'), fileType, AVA_CertImage);790 file.setFolder(request.getParameter('custparam_ava_folderid'));791 var id = nlapiSubmitFile(file);792 var html = '<embed src="https://system.na1.netsuite.com/c.' + nlapiGetContext().getCompany() + '/suitebundle1894/AVA_ExemptionCertificate/' + request.getParameter('custparam_ava_certid') + '.' + request.getParameter('custparam_ava_fileformat') + '" width="550" height="750" type="pdf">';793 }794 AVA_GetCertificatesImageForm.addField('ava_image','help', html, null, 'custpage_avaimagetab');795 }796 else797 {798 var AVA_Messages = nlapiSelectNode( AVA_CertificateImageGetResult, "//*[name()='Messages']");799 var AVA_Message = nlapiSelectValue( AVA_Messages, "//*[name()='Summary']");800 nlapiLogExecution('DEBUG', 'Error Message', AVA_Message);801 nlapiLogExecution('DEBUG', 'Error', AVA_CertificateImageResponse.getCode());802 }803 }804 else805 {806 nlapiLogExecution('DEBUG', 'Please contact the administrator');807 nlapiLogExecution('DEBUG', 'Response Code', AVA_CertificateImageResponse.getCode());808 }809 response.writePage(AVA_GetCertificatesImageForm);810 }811 catch(err)812 {813 nlapiLogExecution('Debug', 'error', err.message);814 }815 }816 }817}818819function AVA_GetCertificatesStatus(request, response)820{821 if(AVA_CheckService('AvaCert2Svc') == 0 && AVA_CheckSecurity( 27 ) == 0)822 {823 if(request.getMethod() == 'GET')824 {825 var AVA_GetCertificatesStatusForm = nlapiCreateForm('Exemption Certificate(s) Status');826 AVA_GetCertificatesStatusForm.setTitle('Exemption Certificate(s) Status');827 828 AVA_ReadConfig('0');829 830 var security = AVA_TaxSecurity(AVA_AccountValue, AVA_LicenseKey);831 var headers = AVA_Header(security);832 var body = AVA_GetCertificatesStatusBody(request.getParameter('customercode'));833 var soapPayload = AVA_BuildEnvelope(headers + body);834 835 var soapHead = new Array();836 soapHead['Content-Type'] = 'text/xml';837 soapHead['SOAPAction'] = '"http://avatax.avalara.com/services/CertificateRequestGet"';838 839 try840 {841 var AVA_CertificateStatusResponse = nlapiRequestURL(AVA_ServiceUrl + '/avacert2/avacert2svc.asmx', soapPayload, soapHead);842 if (AVA_CertificateStatusResponse.getCode() == 200)843 {844 var soapText = AVA_CertificateStatusResponse.getBody();845 var soapXML = nlapiStringToXML(soapText);846 var AVA_ResponseCertificateStatusArray = new Array();847 848 var AVA_CertificateRequestGetResult = nlapiSelectNode(soapXML, "//*[name()='CertificateRequestGetResult']");849 AVA_ResultCode = nlapiSelectValue( AVA_CertificateRequestGetResult, "//*[name()='ResultCode']");850 if (AVA_ResultCode == 'Success') 851 {852 AVA_GetCertificatesStatusForm.addField('ava_customercode','text', 'Customer Code');853 AVA_GetCertificatesStatusForm.getField('ava_customercode').setDefaultValue(request.getParameter('customercode'));854 AVA_GetCertificatesStatusForm.getField('ava_customercode').setDisplayType('inline');855 856 var AVA_CertificateStatusList = AVA_GetCertificatesStatusForm.addSubList('custpage_avacertstatuslist', 'list','Certificate(s) Status Details');857 858 AVA_CertificateStatusList.addField('ava_trackingcode', 'text', 'Tracking Code');859 AVA_CertificateStatusList.addField('ava_requestdate','text', 'Request Date');860 AVA_CertificateStatusList.addField('ava_requeststage','text', 'Request Stage');861 AVA_CertificateStatusList.addField('ava_requeststatus','text', 'Request Status');862 AVA_CertificateStatusList.addField('ava_communicationmode','text', 'Communication Mode');863 864 var CertificatesRequests = nlapiSelectNode(AVA_CertificateRequestGetResult, "//*[name()='CertificateRequests']");865 AVA_ResponseCertificateStatusArray = nlapiSelectNodes(CertificatesRequests, "./*[name()='CertificateRequest']");866 867 for(var i=0; AVA_ResponseCertificateStatusArray != null && i<AVA_ResponseCertificateStatusArray.length ; i++)868 {869 AVA_CertificateStatusList.setLineItemValue('ava_trackingcode', i+1, nlapiSelectValue(AVA_ResponseCertificateStatusArray[i], "./*[name()='TrackingCode']"));870 AVA_CertificateStatusList.setLineItemValue('ava_requestdate', i+1, AVA_DateFormat(nlapiGetContext().getSetting('PREFERENCE', 'DATEFORMAT'),nlapiSelectValue( AVA_ResponseCertificateStatusArray[i], "./*[name()='RequestDate']")));871 var RequestStage = (nlapiSelectValue(AVA_ResponseCertificateStatusArray[i], "./*[name()='RequestStage']") == 'REQUESTINITIATED') ? 'Request Initiated' : ((nlapiSelectValue(AVA_ResponseCertificateStatusArray[i], "./*[name()='RequestStage']") == 'CUSTOMERRESPONDED') ? 'Customer Responded ' : 'Certificate Received');872 AVA_CertificateStatusList.setLineItemValue('ava_requeststage', i+1, RequestStage);873 AVA_CertificateStatusList.setLineItemValue('ava_requeststatus', i+1, nlapiSelectValue(AVA_ResponseCertificateStatusArray[i], "./*[name()='RequestStatus']"));874 AVA_CertificateStatusList.setLineItemValue('ava_communicationmode', i+1, nlapiSelectValue(AVA_ResponseCertificateStatusArray[i], "./*[name()='CommunicationMode']"));875 }876 }877 response.writePage(AVA_GetCertificatesStatusForm);878 }879 }880 catch(err)881 {882 nlapiLogExecution('Debug', 'error', err.message);883 }884 }885 }886}887888function AVA_GetCertificateImageBody(AVA_CertId, FileFormat, Page)889{890 var soap = null;891 soap = '\t<soap:Body>\n';892 soap += '\t\t<CertificateImageGet xmlns="http://avatax.avalara.com/services">\n';893 soap += '\t\t\t<CertificateImageGetRequest>\n';894 soap += '\t\t\t\t\t<CompanyCode><![CDATA[' + nlapiGetContext().getCompany() + ']]></CompanyCode>\n';895 soap += '\t\t\t\t\t<AvaCertId><![CDATA[' + AVA_CertId + ']]></AvaCertId>\n';896 soap += '\t\t\t\t\t<Format>' + FileFormat + '</Format>\n';897 if(FileFormat == 'PNG' && Page != null && Page.length > 0)898 {899 soap += '\t\t\t\t\t<PageNumber><![CDATA[' + Page + ']]></PageNumber>\n';900 }901 soap += '\t\t\t</CertificateImageGetRequest>\n';902 soap += '\t\t</CertificateImageGet>\n';903 soap += '\t</soap:Body>\n';904 905 return soap;906}907908function AVA_CertificateGetBody(CustomerCode)909{910 var soap = null;911 soap = '\t<soap:Body>\n';912 soap += '\t\t<CertificateGet xmlns="http://avatax.avalara.com/services">\n';913 soap += '\t\t\t<CertificateGetRequest>\n';914 soap += '\t\t\t\t\t<CompanyCode><![CDATA[' + nlapiGetContext().getCompany() + ']]></CompanyCode>\n';915 soap += '\t\t\t\t\t<CustomerCode><![CDATA[' + CustomerCode.substring(0,49) + ']]></CustomerCode>\n';916 soap += '\t\t\t</CertificateGetRequest>\n';917 soap += '\t\t</CertificateGet>\n';918 soap += '\t</soap:Body>\n';919 920 return soap;921}922923function AVA_GetCertificatesStatusBody(CustomerCode)924{925 var soap = null;926 soap = '\t<soap:Body>\n';927 soap += '\t\t<CertificateRequestGet xmlns="http://avatax.avalara.com/services">\n';928 soap += '\t\t\t<CertificateRequestGetRequest>\n';929 soap += '\t\t\t\t\t<CompanyCode><![CDATA[' + nlapiGetContext().getCompany() + ']]></CompanyCode>\n';930 soap += '\t\t\t\t\t<CustomerCode><![CDATA[' + CustomerCode.substring(0,49) + ']]></CustomerCode>\n';931 soap += '\t\t\t\t\t<RequestStatus>ALL</RequestStatus>\n';932 soap += '\t\t\t</CertificateRequestGetRequest>\n';933 soap += '\t\t</CertificateRequestGet>\n';934 soap += '\t</soap:Body>\n';935 936 return soap;
...
Using AI Code Generation
1const test = require('ava');2test('foo', t => {3 t.pass();4});5test('bar', async t => {6 const bar = Promise.resolve('bar');7 t.is(await bar, 'bar');8});9"scripts": {10 },11import Vue from 'vue';12import VueResource from 'vue-resource';13import { mount } from 'avoriaz';14import { expect } from 'chai';15import { test } from 'ava';16import { createRenderer } from 'vue-server-renderer';17import { stub } from 'sinon';18import { JSDOM } from 'jsdom';19import { shallow } from 'avoriaz';20import { mount } from 'avoriaz';21import { createLocalVue } from 'avoriaz';22import { createWrapper } from 'avoriaz';23import { createLocalVue } from 'avoriaz';24import { shallowMount } from 'avoriaz';25import { createLocalVue } from 'avoriaz';26import { shallowMount } from 'avoriaz';27import { createLocalVue } from 'avoriaz';28import { shallowMount } from 'avoriaz';29import { mount }
Using AI Code Generation
1import test from 'ava';2test('my passing test', t => {3 t.pass();4});5test('my failing test', t => {6 t.fail();7});8test('my passing test', t => {9 t.is(1, 1);10});11test('my failing test', t => {12 t.is(1, 2);13});14test('my passing test', t => {15 t.not(1, 2);16});17test('my failing test', t => {18 t.not(1, 1);19});20test('my passing test', t => {21 t.true(true);22});23test('my failing test', t => {24 t.true(false);25});26test('my passing test', t => {27 t.false(false);28});29test('my failing test', t => {30 t.false(true);31});32test('my passing test', t => {33 t.truthy(true);34});35test('my failing test', t => {36 t.truthy(false);37});38test('my passing test', t => {39 t.falsy(false);40});41test('my failing test', t => {42 t.falsy(true);43});44test('my passing test', t => {45 t.regex('abc', /abc/);46});47test('my failing test', t => {48 t.regex('abc', /abcd/);49});50test('my passing test', t => {51 t.notRegex('abc', /abcd/);52});53test('my failing test', t => {54 t.notRegex('abc', /abc/);55});56test('my passing test', t => {57 t.deepEqual({a: 1}, {a
Using AI Code Generation
1import test from 'ava';2import { test1 } from './test1';3test('test', t => {4 t.is(test1(), 1);5});6export function test1() {7 return 1;8}9{10 "scripts": {11 },12 "devDependencies": {13 }14}15{16 "scripts": {17 },18 "devDependencies": {19 }20}21import test from 'ava';22import { test1 } from './test1';23test('test', t => {24 t.is(test1(), 1);25});26export function test1() {27 return 1;28}29 × test (1.3s)30 2: import { test1 } from './test1';31 3: import test from 'ava';32 SyntaxError {33 message: 'Unexpected token import',34 }35 test (C:\Users\james\Documents\test\test.js:
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!