Code

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 8

Cash Expenses Search :

I.Daiagram :
1.Get Dates
var today = new Date();
tw.local.endDate = new Date(today.getFullYear(), today.getMonth()+1, 0);
tw.local.startDate = new Date(today.getFullYear(), today.getMonth(), 1);
2. Fetch Cash Expenses - Current Month
Cash Expenses Search GSS:
var processInstanceId = new TWSearchColumn();
processInstanceId.type = TWSearchColumn.Types.ProcessInstance;
processInstanceId.name = TWSearchColumn.ProcessInstanceColumns.ID;
var processInstanceName = new TWSearchColumn();
processInstanceName.type = TWSearchColumn.Types.ProcessInstance;
processInstanceName.name = TWSearchColumn.ProcessInstanceColumns.Name;
var processStatus = new TWSearchColumn();
processStatus.type = TWSearchColumn.Types.ProcessInstance;
processStatus.name = TWSearchColumn.ProcessInstanceColumns.Status;
var processName = new TWSearchColumn();
processName.type = TWSearchColumn.Types.Process;
processName.name = TWSearchColumn.ProcessColumns.Name;
var paidDate = new TWSearchColumn();
paidDate.type = TWSearchColumn.Types.BusinessData;
paidDate.name = 'CE_PaidDate';
var category = new TWSearchColumn();
category.type = TWSearchColumn.Types.BusinessData;
category.name = 'CE_Category';
var subCategory = new TWSearchColumn();
subCategory.type = TWSearchColumn.Types.BusinessData;
subCategory.name = 'CE_SubCategory';
var paidTo = new TWSearchColumn();
paidTo.type = TWSearchColumn.Types.BusinessData;
paidTo.name = 'CE_PaidTo';
var comments = new TWSearchColumn();
comments.type = TWSearchColumn.Types.BusinessData;
comments.name = 'CE_Comments';
var paidBy = new TWSearchColumn();
paidBy.type = TWSearchColumn.Types.BusinessData;
paidBy.name = 'CE_PaidBy';
var amount = new TWSearchColumn();
amount.type = TWSearchColumn.Types.BusinessData;
amount.name = 'CE_Amount';
var approvalStatus = new TWSearchColumn();
approvalStatus.type = TWSearchColumn.Types.BusinessData;
approvalStatus.name = 'CE_ApprovalStatus';
var processStatusCondition = new TWSearchCondition();
processStatusCondition.column = processStatus;
processStatusCondition.operator = TWSearchCondition.Operations.Equals;

processStatusCondition.value = "Terminated";
var processNameCondition = new TWSearchCondition();
processNameCondition.column = processName;
processNameCondition.operator = TWSearchCondition.Operations.Equals;
processNameCondition.value = "Cash Expenses";
/*
var defaultSDF = new Packages.java.text.SimpleDateFormat("E MMM dd HH:mm:ss Z yy
yy");
var defaultDb2SDF = new Packages.java.text.SimpleDateFormat("yyyy-MM-dd HH:MM:SS
.s");
var startDate = tw.local.startDate;
var startDateString = startDate.toString();
var paidDateStart = defaultSDF.parse(startDateString);
var formatedStartDate = defaultDb2SDF.format(paidDateStart);
var db2StartDate = defaultDb2SDF.parse(formatedStartDate);
log.info("----------------------db2StartDate----------------------------------------");
log.info(formatedStartDate);
var endDate = tw.local.endDate;
var endDateString = endDate.toString();
var paidDateEnd = defaultSDF.parse(endDateString);
var formatedEndDate = defaultDb2SDF.format(paidDateEnd);
var db2EndDate = defaultDb2SDF.parse(formatedEndDate);
log.info("----------------------db2EndDate----------------------------------------");
log.info(formatedEndDate);
*/
var paidDateStartCondition = new TWSearchCondition();
paidDateStartCondition.column = paidDate;
paidDateStartCondition.operator = TWSearchCondition.Operations.GreaterThan;
paidDateStartCondition.value = tw.local.startDate.format("MM/dd/yyyy HH:mm:ss",
"PST");
var paidDateEndCondition = new TWSearchCondition();
paidDateEndCondition.column = paidDate;
paidDateEndCondition.operator = TWSearchCondition.Operations.LessThan;
paidDateEndCondition.value = tw.local.endDate.format("MM/dd/yyyy HH:mm:ss", "PST
");
var searchOrdering = new TWSearchOrdering();
searchOrdering.Order = TWSearchOrdering.Orders.Descending;
searchOrdering.column = processInstanceId;
//var selectColumns = new Array(processInstanceId,processInstanceName,processSta
tus,paidDate);
var selectColumns = new Array(processInstanceId,processInstanceName,processStatu
s,paidDate,category,subCategory,paidTo,paidBy,amount,approvalStatus,processName,
comments);
//var searchConditions = new Array(processStatusCondition,processNameCondition);
var searchConditions = new Array(processNameCondition,paidDateStartCondition,pai
dDateEndCondition);
//var searchConditions = new Array(processNameCondition);

var searchOrderings = new Array(searchOrdering);


var search = new TWSearch();
search.organizedBy = TWSearch.OrganizeByTypes.ProcessInstance;
search.columns = selectColumns;
search.conditions = searchConditions;
search.orderBy = searchOrderings;
var results = search.execute();
tw.local.cashExpenses = new tw.object.listOf.CashExpense();
if(results.rows.length > 0){
for(var i= 0;i<results.rows.length;i++){
tw.local.cashExpenses[i] = new tw.object.CashExpense();
var row = results.rows[i];
if(row.values[0]){
tw.local.cashExpenses[i].processInstance = row.values[0].toString();
}
if(row.values[1]){
tw.local.cashExpenses[i].processName = row.values[1].toString();
}
if(row.values[2]){
tw.local.cashExpenses[i].processStatus = row.values[2].toString();
}
if(row.values[3]){
var dateString = row.values[3].toString();
tw.local.cashExpenses[i].paidDate = new Packages.java.text.SimpleDat
eFormat("E MMM dd HH:mm:ss Z yyyy").parse(dateString);
}
if(row.values[4]){
tw.local.cashExpenses[i].category = row.values[4].toString();
}
if(row.values[5]){
tw.local.cashExpenses[i].subCategory = row.values[5].toString();
}
if(row.values[6]){
tw.local.cashExpenses[i].paidTo = row.values[6].toString();
}
if(row.values[7]){
tw.local.cashExpenses[i].paidBy = row.values[7].toString();
}
if(row.values[8]){
tw.local.cashExpenses[i].amount = row.values[8].toString();
}
if(row.values[9] != null){
tw.local.cashExpenses[i].approvalStatus = row.values[9].toString();
if(tw.local.cashExpenses[i].approvalStatus == true && tw.local.cash
Expenses[i].processStatus == "Completed"){
tw.local.cashExpenses[i].approvalStatusStr = "Approved";
}else if(tw.local.cashExpenses[i].approvalStatus == false && tw.loca
l.cashExpenses[i].processStatus == "Completed"){
tw.local.cashExpenses[i].approvalStatusStr = "Rejected";
}else if(tw.local.cashExpenses[i].approvalStatus == false && tw.loca
l.cashExpenses[i].processStatus == "Active"){
tw.local.cashExpenses[i].approvalStatusStr = tw.local.pending;
//tw.local.cashExpenses[i].approvalStatusStr = "<span style = 'c
olor : red;'>" + tw.local.pending + "</span>";
}

}
if(row.values[10]){
tw.local.cashExpenses[i].mainProcessName = row.values[10].toString()
;
}
if(row.values[11]){
tw.local.cashExpenses[i].comments = row.values[11].toString();
}
}
}

3. Cash Expenses Coach:


1.Filter Results:
var monthToken = tw.local.searchSelected.selectedMonth.value.spl
it("-");
tw.local.startDate.setFullYear(Number(monthToken[1]));
tw.local.startDate.setMonth(Number(monthToken[0]));
tw.local.endDate = new Date(tw.local.startDate.getFullYear(), tw
.local.startDate.getMonth()+1, 0);
2. Filter Cash Expenses:
Cash Expenses Search GSS:
3. Validation Service:
Default Validation Service:
tw.local.coachValidation = new tw.object.CoachValidation
();
if (tw.local.searchSelected.selectedFinancialYear.length
<=0 || tw.local.searchSelected.selectedFinancialYear == undefined){
tw.system.addCoachValidationError(tw.local.coachValidati
on, "tw.local.searchSelected.selectedFinancialYear", "FinancialYear is Required!
, Please Select FinancialYear");
}
if (tw.local.searchSelected.selectedMonth.value.length<=
0 || tw.local.searchSelected.selectedMonth.value == undefined){
tw.system.addCoachValidationError(tw.local.coachValidati
on, "tw.local.searchSelected.selectedMonth", " Month is Required!, Please Select
Month");
}
II . Varialbles :
Private Variables :
1. cashExpenses(cashExpense)
2. searchSelected(SearchSelected)
selectedFinancialYear
selectedMonth
III. Selected Search CV:
1. Custom HTML :
<style>
.claro .BPMButton .dijitButton .dijitButtonNode {
height: 26px;
color: #f2f2f2;
background-color: #1b69a9;
-moz-border-radius: 4px;

border-radius: 4px;
text-align: center;
font-size: 14px;
font-weight: bold;
background-repeat: repeat-x;
padding-bottom: 0px;
border: 1px solid #21486c;
border-top-color: #4178aa;
border-left-color: #4178aa;
border-bottom-color: #21486c;
border-right-color: #21486c;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#1B76BC',
endColorstr='#124B80');
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#1B76BC',
endColorstr='#124B80')";
background-position: 0px 0px;
background-image: linear-gradient(bottom, #124B80 0%, #1B76BC 100%);
background-image: -o-linear-gradient(bottom, #124B80 0%, #1B76BC 100%);
background-image: -moz-linear-gradient(bottom, #124B80 0%, #1B76BC 100%);
background-image: -webkit-linear-gradient(bottom, #124B80 0%, #1B76BC 100%);
background-image: -ms-linear-gradient(bottom, #124B80 0%, #1B76BC 100%);
background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0,
#124B80),
color-stop(1, #1B76BC) );
}
.claro .BPMButton .dijitButton .dijitButtonNode:hover {
color: #fff;
border-top-color: #4178aa;
border-left-color: #4178aa;
border-bottom-color: #21486c;
border-right-color: #21486c;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#429CE2',
endColorstr='#124B80');
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#429CE2',
endColorstr='#124B80')";
background-image: linear-gradient(bottom, #124B80 0%, #429CE2 100%);
background-image: -o-linear-gradient(bottom, #124B80 0%, #429CE2 100%);
background-image: -moz-linear-gradient(bottom, #124B80 0%, #429CE2 100%);
background-image: -webkit-linear-gradient(bottom, #124B80 0%, #429CE2 100%);
background-image: -ms-linear-gradient(bottom, #124B80 0%, #429CE2 100%);
background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0,
#124B80),
color-stop(1, #429CE2) );
-moz-box-shadow: 0 2px 3px rgba(0,0,0,.5);
-webkit-box-shadow: 0 2px 3px rgba(0,0,0,.5);
box-shadow: 0 2px 3px rgba(0,0,0,.5);
}
.claro .BPMButton .dijitButtonDisabled .dijitButtonNode, .claro .myBPMButton .di
jitButtonDisabled .dijitButtonNode:hover {
color: #a0a0a0;
background-color: #113f66;
cursor: not-allowed;
}
.BPMButton .dijitDisabled * {
cursor: not-allowed;
}
.BPMButton .dijitButtonText {
margin-top: 2px;

}
</style>

2. Month Selection Service:


if(tw.local.text != undefined && tw.local.text.length >0 && tw.local.tex
t != ""){
var tokens = tw.local.text.split("-");
/*
tw.local.results = new tw.object.listOf.String();
tw.local.results[0] = "April, "
+((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[1] = "May, "
+((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[2] = "June, "
+((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[3] = "July, "
+((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[4] = "August, "
+((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[5] = "September, " +((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[6] = "October, " +((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[7] = "November, " +((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[8] = "December, " +((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[9] = "January, " +((Number(tokens[1]) > Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[10] = "February, " +((Number(tokens[1]) > Number(tokens[0])
)?tokens[1]:tokens[0]);
tw.local.results[11] = "March, "
+((Number(tokens[1]) > Number(tokens[0])
)?tokens[1]:tokens[0]);
*/
tw.local.results = new tw.object.listOf.NameValuePair();
tw.local.results[0] = new tw.object.NameValuePair();
tw.local.results[0].name = "April, "+((Number(tokens[1]) < Number(tokens[0]))?to
kens[1]:tokens[0]);
tw.local.results[0].value = "3-"+((Number(tokens[1]) < Number(tokens[0]))?tokens
[1]:tokens[0]);
tw.local.results[1]= new tw.object.NameValuePair();
tw.local.results[1].name = "May, "+((Number(tokens[1]) < Number(tokens[0]))?toke
ns[1]:tokens[0]);
tw.local.results[1].value = "4-"+((Number(tokens[1]) < Number(tokens[0]))?tokens
[1]:tokens[0]);
tw.local.results[2] = new tw.object.NameValuePair();
tw.local.results[2].name = "June, "+((Number(tokens[1]) < Number(tokens[0]))?tok
ens[1]:tokens[0]);
tw.local.results[2].value = "5-"+((Number(tokens[1]) < Number(tokens[0]))?tokens
[1]:tokens[0]);

tw.local.results[3] = new tw.object.NameValuePair();


tw.local.results[3].name = "July, "+((Number(tokens[1]) < Number(tokens[0]))?tok
ens[1]:tokens[0]);
tw.local.results[3].value = "6-"+((Number(tokens[1]) < Number(tokens[0]))?tokens
[1]:tokens[0]);
tw.local.results[4] = new tw.object.NameValuePair();
tw.local.results[4].name = "August, "+((Number(tokens[1]) < Number(tokens[0]))?t
okens[1]:tokens[0]);
tw.local.results[4].value = "7-"+((Number(tokens[1]) < Number(tokens[0]))?tokens
[1]:tokens[0]);
tw.local.results[5] = new tw.object.NameValuePair();
tw.local.results[5].name = "September, " +((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[5].value = "8-"+((Number(tokens[1]) < Number(tokens[0]))?tokens
[1]:tokens[0]);
tw.local.results[6] = new tw.object.NameValuePair();
tw.local.results[6].name = "October, " +((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[6].value = "9-"+((Number(tokens[1]) < Number(tokens[0]))?tokens
[1]:tokens[0]);
tw.local.results[7] = new tw.object.NameValuePair();
tw.local.results[7].name = "November, " +((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[7].value ="10-"+((Number(tokens[1]) < Number(tokens[0]))?tokens
[1]:tokens[0]);
tw.local.results[8] = new tw.object.NameValuePair();
tw.local.results[8].name = "December, " +((Number(tokens[1]) < Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[8].value = "11-"+((Number(tokens[1]) < Number(tokens[0]))?token
s[1]:tokens[0]);
tw.local.results[9] = new tw.object.NameValuePair();
tw.local.results[9].name = "January, " +((Number(tokens[1]) > Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[9].value ="0-" +((Number(tokens[1]) > Number(tokens[0]))?toke
ns[1]:tokens[0]);
tw.local.results[10] = new tw.object.NameValuePair();
tw.local.results[10].name = "February, " +((Number(tokens[1]) > Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[10].value ="1-" +((Number(tokens[1]) > Number(tokens[0]))?token
s[1]:tokens[0]);
tw.local.results[11] = new tw.object.NameValuePair();
tw.local.results[11].name = "March, "
+((Number(tokens[1]) > Number(tokens[0]
))?tokens[1]:tokens[0]);
tw.local.results[11].value = "2-"
+((Number(tokens[1]) > Number(tokens[0]))?t
okens[1]:tokens[0]);
}
3. Financial Year CV :
Financial Year Selection Service:

tw.local.results = new tw.object.listOf.String();


tw.local.results[0] = "2010-2011";
tw.local.results[1] = "2011-2012";
tw.local.results[2] = "2012-2013";
tw.local.results[3] = "2013-2014";
tw.local.results[4] = "2014-2015";
tw.local.results[5] = "2015-2016";
tw.local.results[6] = "2016-2017";
tw.local.results[7] = "2017-2018";
tw.local.results[8] = "2018-2019";
tw.local.results[9] = "2019-2020";

You might also like