域名已变更 请手动修改文章中域名指向carlzeng.com

netsuite固定资产模块之client端,资产dispose处理,revaluation再评估,depreciation折旧,registerReport资产注册报表,DepreciationScheduleReport折旧定期报表,AssetsStatus固定资产状态,SystemSetup注册安装模块,SummaryReport汇总报表

下面介绍一下,我分析 资产, 财产asset的一些结论,全是netsuite的固定资产解决方案,希望对您有些帮助。~
总体分类如下:

模块一:proposal 提议; 建议
模块二:资产dispose处理,
模块三:revaluation再评估,
模块四:depreciation折旧,
模块五:registerReport资产注册报表,
模块六:DepreciationScheduleReport折旧定期报表,
模块七:AssetsStatus固定资产状态,
模块八:SystemSetup注册安装模块
模块九:SummaryReport汇总报表

模块一:proposal 提议; 建议

-------------------------------------------------------------------- 以下是操作界面:proposal 提议

function ncFAR_ProposalSL(request, response)
{
var RKResp = nlapiRequestURL( RKcheckURL, null, RKparams ); // params now passed as custom headers
var RKresult = RKResp.getBody().split(':'); 请求一个验证注册的sl,然后进一步判断。

if (request.getMethod() == 'GET') // page display
{
var Params = new Array();
ncFAR_RenderProposalForm(PropList,'Edit',null,null,Params); //初始化一个列表,或sublist
response.writePage(PropList);
}
else // user submit
{
var rParams = request.getAllParameters();

if( rParams['ncactionid'] == 'Propose' ) //动作1:建议
else if( rParams['ncactionid'] == 'Generate' )//动作2:生成
var ProposalList = new Array();
for(var i=1; i<=request.getLineItemCount('proposals'); ++i) //在最开始的页面上,submit后直接getLineItemCount ;经典应用!
else if( rParams['ncactionid'] == 'Reject' ) //动作3:拒绝
for(var i=1; i<=request.getLineItemCount('proposals'); ++i) //经典应用zeng.cz200901051710;说明了submit以后request本身成为了一种Record可以直接getLineItemValue等动作,这个应用非常经典。其他main的变量都可以request.getAllParameters()中取道。
{
if( request.getLineItemValue('proposals','marked',i) == 'T' )
{
nlapiSubmitField(ncConst.FAR_Proposal,request.getLineItemValue('proposals','id',i),
'custrecord_propstatus','4',false); // 10 units not 30!
}
}

}

function ncFAR_RenderProposalForm(form,recState,id,rec,params) //This function builds the tabs, fields and buttons for the Asset Proposal window
{
// header area Filter expressions
var f_msAssetType = params['filter_msAssetType'];
if( f_msAssetType == null ) f_msAssetType = '';

var fld0 = form.addField('ncactionid','text','Action Id');
fld0.setDisplayType('hidden');
fld0.setDefaultValue('');

var pList = form.addSubList('proposals','list','Proposed Assets');

pList.addField('editurl','url','Edit',true).setLinkText('Edit');
pList.addField('custrecord_propassetdescr','text','Description').setDisplayType('inline'); //简写经典应用。
pList.addField('custrecord_propaccmethod','select','Depreciation Method',ncConst.FAR_DeprMethod).setDisplayType('inline');
pList.addField('custrecord_propassetcost','currency','Initial Cost').setDisplayType('inline');

pList.addMarkAllButtons();

form.addSubmitButton('Refresh');
form.addButton('Propose','Propose New Assets',"if (window.isinited && window.isvalid && save_record(true)){main_form.ncactionid.value='Propose';main_form.submit();}");
form.addButton('Generate','Generate Assets',"if (window.isinited && window.isvalid && save_record(true)){main_form.ncactionid.value='Generate';main_form.submit();}");
form.addButton('Reject','Reject Proposals',"if (window.isinited && window.isvalid && save_record(true)){main_form.ncactionid.value='Reject';main_form.submit();}"); //经典应用2:main_form.ncactionid.value='Propose' 这样给一个'ncactionid' 页面隐藏的变量赋值了!! 然后main_form.submit()以后request.getAllParameters()就可以得到所有这些字段的值(包括隐藏的字段),然后再if( rParams['ncactionid'] == 'Propose' )进行动作判断。
200901051702
zeng.cz

动作 完毕!~ 书写系统日志 经典:

/* ncBGP_WriteToLog - utility function to write to the Background Process Manager log table
*
* This function will create a new NC Process Log record using the details provided
*
* Parameters:
* ProcessId - the id of the current process record
* RecordRef - a reference for the current record being processed or which the message relates to
* MessageText - the message text to be written to the log
* MessageType - the type of message, 'Error', 'Warning' or 'Message'
*/
function ncBGP_WriteToLog(ProcessId,RecordRef,MessageText,MessageType)
{
var l_MsgType;
switch (MessageType)
{
case 'Error':
l_MsgType = 1;
break;

case 'Warning':
l_MsgType = 2;
break;

case 'Message':
default:
l_MsgType = 3;
}

var LogRec = nlapiCreateRecord('customrecord_ncbgp_processlog');
LogRec.setFieldValue('custrecord_logprocessid',ProcessId);
LogRec.setFieldValue('custrecord_logrecordref',RecordRef);
LogRec.setFieldValue('custrecord_logmessagetype',l_MsgType);
LogRec.setFieldValue('custrecord_logmessagedetail',MessageText);
nlapiSubmitRecord(LogRec,false);
}

模块二:dispose 处理;处置

DisposalPageInit - Event Script for Page Init to disable or enable fields
Once sold or disposed, everything should be read-only

onload. assetid change
var Rec = nlapiLoadRecord('customrecord_ncfar_asset', Id);
nlapiSetFieldValue('assetdescr', ncToEmptyString(Rec.getFieldValue('custrecord_assetdescr')));
DisposalPageInit();

AssetOnSave
Please select a Disposal Type
Sale amount must be greater than zero

-------------------------------------------------------------------- 以下是操作界面:dispose 处理

1,ncFAR_RenderDisposalForm(DisposalForm,'New',null,null,Params);

2,submit后创建form; 总体circle的经典应用

var dParams = request.getAllParameters();
var assetId = dParams['assetid'];
var dAsset;
if( (assetId != null) && (assetId != '') )
{
dAsset = nlapiLoadRecord(ncConst.FAR_Asset, assetId);
}

var result = AssetDisposal(dAsset, assetId, dParams); //根据提交的id 和变量信息,提交给第三步的事务处理来解决
if(result !='')
{
// disposal failed
ncFAR_RenderDisposalForm(DisposalForm, 'Error', assetId, dAsset, dParams,result); //如果出错则 创建form
response.writePage(DisposalForm);
}
else
{
//disposal successful - redirect to full view of asset //如果成功,直接跳转业务流程。
response.sendRedirect('RECORD',ncConst.FAR_Asset,assetId,false); //suitelet良好应用sendRedirect

3,处理特殊具体的事务

* Generate disposal journal and update asset status.
* Generate asset history record.
* If a Sale, create Sales Invoice record and update link on Asset.

// if Sale
if( DispType == 1 )
var usermsg = '<BR>Failed to create invoice for asset sale. <BR>Check setup of location and subsidiary on asset record.';
var result = CreateJournalEntry(DispDate,CurrencyId,FixedExchangeRate,accts,debits,credits,refs,JournalId,Subsid,ClassId,DepartmentId,LocationId);
fNames = new Array('custrecord_assetstatus', 'custrecord_assetdepractive','custrecord_assetbookvalue','custrecord_assetdisposaldate', 'custrecord_assetdisposaltype', 'custrecord_assetdisposalitem', 'custrecord_assetsalecustomer', 'custrecord_assetsaleamount', 'custrecord_assetsalesinvoice');
fValues = new Array('4', '2','0.00',DispDate, DispType, SaleItem, CustomerId, SaleAmount, SIrecId);
nlapiSubmitField('customrecord_ncfar_asset', id, fNames, fValues, 'F'); //经典应用,数组批量的submitField
// if Write Off
else if( DispType == 2 )
msg = result + '<BR>Journal entry for asset write-off not created.'; //make JE
nlapiSubmitField('customrecord_ncfar_asset', id, fNames, fValues, 'F');//更新资产
var rDeprHist = nlapiCreateRecord(ncConst.FAR_DeprHistory); //书写历史。


模块三:revaluation 再评估

if(nlapiGetFieldText('assetstatus') == 'Disposed')
alert('This asset has been disposed.');

save
Revaluation details must be supplied;

-------------------------------------------------------------------- 以下是操作界面:revaluation 再评估

三个结构,思路很清晰:

1。构造主界面如果是request.getMethod() == 'GET') // page display显示
构造初始form然后writePage。 else 获得request 的参数开始运算过程

2。书写构造form的函数,subtab等的界面按钮等。

3。ncFAR_ProcessRevaluation进行运算。书写JE,完成系统内部联系。

模块四:depreciation 折旧

/* DeprMethodOnSave - Event Script to invoke validation and display error if failed (and prevent save)
*
* This function will use SL_DeprMethodValidate (suitelet function) to validate the formula.
* If the formula parses successfully it will continue the save operation.
* If the formula fails an error is displayed and the save is aborted.
*/

var SLparams = new Array();
SLparams['deprmethodformula'] = l_Fn;
SLparams['render'] = 'false';
var OnSaveURL = nlapiResolveURL('SUITELET','customscript_ncfar_deprmethodvalidate','customdeploy_ncfar_deprmethodvalidate',true);
var OnSaveResp = nlapiRequestURL( OnSaveURL, SLparams );
var OnSaveResult = OnSaveResp.getBody().split('~');

if( OnSaveResult[0] == 'OK' )
{

document.all.item('divNCFN').innerHTML = OnSaveResult[1];
alert('Function validated successfully. Please review formula representation.');

-------------------------------------------------------------------- 以下是操作界面:RenderDepreciate

留在后期在补充。。200812111500

var fNames = new Array();
fNames[0] = 'custrecord_currentprocessstatus';
fNames[1] = 'custrecord_processactivitytype';
fNames[2] = 'custrecord_numrecordsprocessed';
fNames[3] = 'custrecord_processfailuremessage';
fNames[4] = 'custrecord_processparamnames';
fNames[5] = 'custrecord_processparamvalues';
var fValues = new Array();
fValues[0] = '1'; // status 1 = in progress
fValues[1] = '1'; // activity type 1 = custom (direct call)
fValues[2] = '0'; // reset record count
fValues[3] = ''; // reset error message
fValues[4] = 'ATarray,ATypes,DeprPeriod';
fValues[5] = ATlist+','+ATlist+','+DeprPeriodDate;

nlapiSubmitField(ncConst.NC_ProcessActivity, ProcessId, fNames, fValues, false); //经典应用,....数组赋值,多字段submit,ncConst.NC_ProcessActivity 全局变量中取值
ncFAR_DepreciateAssetBG(ProcessId); //should be in main transfer function

模块五:registerReport 资产注册报表

Client code for Asset Register Report scriptlet

ncFAR_AssetRegisterReportSL - entry point for Asset Register Report Scriptlet

form.addSubmitButton('Generate Report');

suitelet:

var AssetReportForm = nlapiCreateForm('Asset Register Report');

var ReportOptions = new Array();

if (request.getMethod() == 'GET') // page display //在显示之前,先把form等变量定义好
{
var Params = new Array();
ncFAR_RenderReportOptionsForm(AssetReportForm,'Edit',null,null,Params);
response.writePage(AssetReportForm);
}
else // user submit
{
var rParams = request.getAllParameters(); //这个方法 取得那些变量

ReportOptions[0] = rParams['filtermsassettype'];
ReportOptions[1] = rParams['filtermssubsid'];

var fld_rptData = AssetReportForm.addField('reportdata', 'inlinehtml', ''); //用户点击提交后改变或添加一些field,然后设置值 然后再writePage 这个form即可!! 经典应用!高效 的动态刷新了页面。
fld_rptData.setDisplayType('inline'); //因为是inlinehtml的类型 并且设置显示类型:inline 所以结构就灵活了。。。
fld_rptData.setDefaultValue( ncFAR_BuildReportData(ReportOptions, response) );
response.writePage(AssetReportForm);
}

模块六:Depreciation Schedule Report 折旧定期报表

// aiming to make the following table structure:
//
// [ ][ Asset Type Name 1 ][ Asset Type Name 2 ]...
// ['Asset'][Asset No.<br>Name][Asset No.<br>Name]... [Asset No.<br>Name][Asset No.<br>Name]...
// [period1][depr amt][nbv amt][depr amt][nbv amt] [depr amt][nbv amt][depr amt][nbv amt]
// [period2][depr amt][nbv amt][depr amt][nbv amt] [depr amt][nbv amt][depr amt][nbv amt]
// [... ][depr amt][nbv amt][depr amt][nbv amt] [depr amt][nbv amt][depr amt][nbv amt]
//
// so, outer table for 3 columns, n periods + 2 rows; each row (except first) contains sub-table for cols 2 and 3

while( (srAT != null) && (i < srAT.length) )
{
while( (srAssets != null) && (j < srAssets.length) )
{ ++j;
}
++i;
}

Asset Depreciation Schedule - Period Depreciation 折旧期间

Asset Depreciation Schedule - Net Book Value

模块七: Fixed Assets Status固定资产状态

处理状态报告,搜索状态表,
var sr = nlapiSearchRecord('customrecord_ncbgp_processcontrol',null,sf,sc);

var rProcessInfo = sr[0];
var procStatus = rProcessInfo.getValue('custrecord_currentprocessstatus'); //get text
var procStatusText = rProcessInfo.getText('custrecord_currentprocessstatus');
var l_RecordCount = rProcessInfo.getValue('custrecord_numrecordsprocessed');

fld_1.setDefaultValue(procStatusText);

var _InProgress = false;
if(procStatus == '1' || procStatus == '5') // In Progress or In Queue
_InProgress = true;

if(_InProgress)

else // processing complete
{
fld_3.setDefaultValue(l_RecordCount + ' assets(s) have been depreciated.');
}

模块八: SystemSetup注册安装模块

三个结构,思路很清晰:

1。构造主界面如果是request.getMethod() == 'GET') // page display显示
构造初始form然后writePage。 else 获得request 的参数开始运算过程

2。先判断是new的setup还是edit的form,然后书写构造form的函数,subtab等的界面及按钮等。
如果有ncConst.FAR_SystemSetup记录的话,把默认的系统设置带出来,并且把配置信息子标签和内容都弄出来。
如果没有就只弄出界面而已,不包含配置Subsidiaries、Departments、Locations、Classes、Jobs、Multiple Currencies的checkbox。


ncFAR_RenderSetupForm(form,setupState,id,rec)
var fld1 = form.addField('farsetupautopropose', 'checkbox', 'Auto-Propose from Asset Accounts', '', 'custpagesettings');
var fld1b = form.addField('farsetupautocreate', 'checkbox', 'Auto-Create from Asset Accounts', '', 'custpagesettings');
var fld2 = form.addField('farsetuppostlocation', 'checkbox', 'Post on Location Change', '', 'custpagesettings');
var fld3 = form.addField('farsetuppostclass', 'checkbox', 'Post on Class Change', '', 'custpagesettings');
var fld4 = form.addField('farsetuppostdepartment', 'checkbox', 'Post on Department Change', '', 'custpagesettings');
var fld4b = form.addField('farsetupsummaryjournals', 'checkbox', 'Summarise Depreciation Journals', '', 'custpagesettings'
var fldAFD = form.addField('farsetupfuturedepreciations', 'checkbox', 'Allow Future-dated Depreciation', '', 'custpagesettings');
if (setupState == 'Edit') // 如果是要编辑一些系统设置的话,
{
fld1.setDefaultValue(rec.getFieldValue('custrecord_autopropose'));
form.addTab('custpagefeatures', 'Features');

var fld6 = form.addField('farsetupsubsidsenabled', 'checkbox', 'Subsidiaries', '', 'custpagefeatures');
var hiddenIDField = form.addField('hidden_field', 'text', 'hidden');
hiddenIDField.setDisplayType('hidden');
hiddenIDField.setDefaultValue(id); //如果是编辑,把id带过去。
form.addSubmitButton('Save');
}
else
{
fld1.setDefaultValue('T'); // checked
fld1b.setDefaultValue('T'); // checked
form.addSubmitButton('Submit');
}

3。else(即submit后)进行运算:先CreateRecord创建记录

var rec = nlapiCreateRecord(ncConst.FAR_SystemSetup);
rec.setFieldValue('custrecord_allowfuturedepr', request.getParameter('farsetupfuturedepreciations'));
rec.setFieldValue('custrecord_subsidsenabled', currentContext.getSetting('FEATURE', 'subsidiaries'));
var id = request.getParameter('hidden_field'); //用request中隐含字段带出id
if( id != null )
{
rec.setFieldValue('id', id); //关键语句
}
try {
id = nlapiSubmitRecord(rec); //关键语句;经典应用,如果是edit的话(有id),submitRecord系统就会更新原有记录,如果没有就会创建一条!!
} catch (e) {
if ( e instanceof nlobjError )
nlapiLogExecution('Error','System Setup Suitelet', e.getCode() + '\n' + e.getDetails());
else
nlapiLogExecution('Error','System Setup Suitelet', e.toString());
}

var form = nlapiCreateForm('Fixed Assets Register'); //经典应用二! submit后直接在CreateForm然后把id赋予直接创建form然后writePage.!!  完美circle!
ncFAR_RenderSetupForm(form,'Edit',id,rec);
response.writePage(form);


模块九:SummaryReport汇总报表

关键点:ncFAR_BuildReportData(ReportOptions)
* This function will read through the Asset data, filtering by the given Report
* Options, and convert the results to HTML
*
* Parameters: ReportOptions - Array of range values to restrict the report data

模块十:核心主函数

if( currentContext.getSetting('FEATURE','multicurrency') == 'T' ) //for what?
{
sColumns[sColumns.length] = new nlobjSearchColumn('currency'); // N.B. this (as at 9 Nov 2007) will return currency id (not name)
sColumns[sColumns.length] = new nlobjSearchColumn('exchangerate'); //good way!~`
}



全局变量设定:

/* ************* Shared Constant Values ************* */

function ncConst() // dummy constructor for ncConst object which will contain our Record Type constants
{
}

ncConst.BGP_ProcessIdParam = 'custscript_bgp_processid'; /* parameter name for Process Id on scheduled script deployments */
ncConst.BGP_ProcessIdParam2 ='custscript_bgp_startprocessid'; /* parameter name for Process Id on additional scheduled script deployments */

//--SEARCHBLOCK:customrecord - replace these values on deployment
ncConst.FAR_SystemSetup = 'customrecord_ncfar_systemsetup'; /* record type for System Setup */
ncConst.FAR_AssetType = 'customrecord_ncfar_assettype'; /* record type for Asset Type */
ncConst.FAR_DeprMethod = 'customrecord_ncfar_deprmethod'; /* record type for Deprecation Method */
ncConst.FAR_Asset = 'customrecord_ncfar_asset'; /* record type for Asset */
ncConst.FAR_Proposal = 'customrecord_ncfar_assetproposal'; /* record type for Asset Proposal */
ncConst.FAR_AssetUsage = 'customrecord_ncfar_assetusage'; /* record type for Asset Usage */
ncConst.FAR_DeprHistory = 'customrecord_ncfar_deprhistory'; /* record type for Depreciation History */
ncConst.FAR_XferAccounts = 'customrecord_ncfar_transferaccounts'; /* record type for Asset Transfer Accounts */
ncConst.NC_ProcessActivity = 'customrecord_ncbgp_processcontrol'; /* record type for Process Activity */
ncConst.NC_ProcessLog = 'customrecord_ncbgp_processlog'; /* record type for Process Log */

posted @ 2008-12-10 15:02  CarlZeng  阅读(743)  评论(0编辑  收藏  举报
域名已变更 请手动修改文章中域名指向carlzeng.com