📄 forecastdetail.jsp
字号:
<%@ page import="org.ofbiz.entity.*" %>
<%@ page import="org.ofbiz.entity.model.*" %>
<%@ page import="java.lang.reflect.Method" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.math.*" %>
<%@ page import="java.sql.Timestamp" %>
<%@ page import="org.ofbiz.entity.util.SequenceUtil" %>
<%@ include file="/includes/header.jsp" %>
<%!
double computeQuotaPercent(double firstNum, double secNum){
if(secNum==0) return 0.0;
DecimalFormat decimalFormat = new DecimalFormat("#.##");
return Double.valueOf(decimalFormat.format(firstNum / secNum)).doubleValue();
}
%>
<%
String userName = (String)session.getAttribute("userName");
String partyId = (String)session.getAttribute("partyId");
int month = (request.getParameter("month") == null ? 0 : Integer.parseInt(request.getParameter("month")));
int year = (request.getParameter("year") == null ? 0 : Integer.parseInt(request.getParameter("year")));
if(month == 0){
month = Calendar.getInstance().get(Calendar.MONTH) + 1;
}
if(year == 0){
year = Calendar.getInstance().get(Calendar.YEAR);
}
int quarterNumbers[] = getQuarterMonthNumbers(month);
String quarter[] = getQuarterMonthNames(month);
String ENTITY = "Forecast";
String PARTY = "Party";
String action = "";
ModelEntity entity = delegator.getModelEntity(ENTITY);
if(request.getParameter("action") != null){
//actions=search, update, create
action = request.getParameter("action");
}
if(action.equals("update")){
GenericValue genericValue = new GenericValue(entity);
genericValue.setDelegator(delegator);
Vector forecastFields = entity.getFieldsCopy();
ModelField modelField = null;
Enumeration params = request.getParameterNames();
while(params.hasMoreElements()){
String pName = (String)params.nextElement();
modelField = entity.getField(pName);
if((modelField = contains(forecastFields, pName)) != null){
genericValue = setCorrectDataType( genericValue, modelField, request.getParameter(pName));
}
}
genericValue.set("modifiedBy", "testUser");
genericValue.set("modifiedDate", new Timestamp(new java.util.Date().getTime()));
delegator.store(genericValue);
}
//get deal details
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, month - 1);
cal.set(Calendar.YEAR, year);
ArrayList list = new ArrayList();
list.add(new EntityExpr("ownerId", EntityOperator.EQUALS, session.getAttribute("partyId")));
list.add(new EntityExpr("projectedCloseDate", EntityOperator.LESS_THAN_EQUAL_TO, new java.sql.Date( getMaximumQuarterDate((cal.get(Calendar.MONTH) + 1)).getTime())));
list.add(new EntityExpr("projectedCloseDate", EntityOperator.GREATER_THAN_EQUAL_TO, new java.sql.Date( getMinimumQuarterDate((cal.get(Calendar.MONTH) + 1)).getTime())));
list.add(new EntityExpr("isInForecast", EntityOperator.EQUALS, "1"));
ArrayList order = new ArrayList();
order.add("projectedCloseDate");
List dealList = delegator.findByAnd("Deal", list, order);
List dealStatus = delegator.findAll("DealStatus", null);
List dealStage = delegator.findAll("DealStage", null);
GenericValue dealValues[] = (GenericValue[])dealList.toArray(new GenericValue[0]);
//Forecast
int quarters[] = getQuarterMonthNumbers(month);
ArrayList forecastList = new ArrayList();
forecastList.add(new EntityExpr("contactId", EntityOperator.EQUALS, userInfo.getPartyId()));
forecastList.add(new EntityExpr("month", EntityOperator.GREATER_THAN_EQUAL_TO, new Long(quarters[0])));
forecastList.add(new EntityExpr("month", EntityOperator.LESS_THAN_EQUAL_TO, new Long(quarters[2])));
forecastList.add(new EntityExpr("year", EntityOperator.EQUALS, new Long(year)));
List forecastList = delegator.findByAnd("Forecast", forecastList, null);
GenericValue forecastValues[] = (GenericValue[])forecastList.toArray(new GenericValue[0]);
//Accounts
HashMap accountFields = new HashMap();
accountFields.put("accountOwnerId", session.getAttribute("partyId"));
List accountList = delegator.findByAnd("Account", accountFields);
double sumClosed = 0.0;
int countClosed = 0;
double sumForecast = 0.0;
int countForecast = 0;
double sumCommit = 0.0;
int countCommit = 0;
double sumUpside = 0.0;
int countUpside = 0;
double sumLongshot = 0.0;
int countLongshot = 0;
double sumProspect = 0.0;
int countProspect = 0;
double sumInactive = 0.0;
int countInactive = 0;
double sumLost = 0.0;
int countLost = 0;
double sumOpportunities = 0.0;
GenericValue dealValue = null;
GenericValue forecastValue = null;
for(int iz=0;iz<dealValues.length;iz++) {
dealValue = dealValues[iz];
Calendar calendar = Calendar.getInstance();
calendar.setTime(dealValue.getDate("projectedCloseDate"));
double amount = dealValue.getDouble("amount").doubleValue();
sumOpportunities = sumOpportunities + amount;
int dealStatusId = Integer.valueOf(dealValue.getString("dealStatusId")).intValue();
if(dealValue.get("dealStatusId").equals("1")){ //closed
sumClosed = sumClosed + amount;
countClosed++;
} else { //forecasted
if(dealValue.getString("isInForecast") != null && dealValue.getString("isInForecast").equals("1"))
sumForecast = sumForecast + amount;
countForecast++;
switch(dealStatusId){
case 2: //commit
sumCommit = sumCommit + amount;
countCommit++;
break;
case 3: //upside
sumUpside = sumUpside + amount;
countUpside++;
break;
case 4: //longshot
sumLongshot = sumLongshot + amount;
countLongshot++;
break;
case 5: //prospect
sumProspect = sumProspect + amount;
countProspect++;
break;
case 6: //inactive
sumInactive = sumInactive + amount;
countInactive++;
break;
case 7: //lost
sumLost = sumLost + amount;
countLost++;
break;
}
}
}
%>
<style>
td { border-width: 0pt;border-right-width: 1pt;border-bottom-width: 1pt;border-style: solid;border-color: black; font-family: sans-serif;}
tdHead { border-width: 0pt;border-right-width: 1pt;border-bottom-width: 1pt;border-style: solid;border-color: black; font-family: sans-serif;font-weight: bold;}
</style>
<form method="post" action="<ofbiz:url>/forecastDetail</ofbiz:url>" name="MonthForm">
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td style="border-color: white;font-weight: bold;font-family: sans-serif;">Month</td>
<td style="border-color: white;font-weight: bold;font-family: sans-serif;">
<select name="month" onchange="document.MonthForm.submit();">
<option value='1' <%if(month==1){%> selected <%}%>>January
<option value='2' <%if(month==2){%> selected <%}%>>February
<option value='3' <%if(month==3){%> selected <%}%>>March
<option value='4' <%if(month==4){%> selected <%}%>>April
<option value='5' <%if(month==5){%> selected <%}%>>May
<option value='6' <%if(month==6){%> selected <%}%>>June
<option value='7' <%if(month==7){%> selected <%}%>>July
<option value='8' <%if(month==8){%> selected <%}%>>August
<option value='9' <%if(month==9){%> selected <%}%>>September
<option value='10' <%if(month==10){%> selected <%}%>>October
<option value='11' <%if(month==11){%> selected <%}%>>November
<option value='12' <%if(month==12){%> selected <%}%>>December
</select>
</td>
<td style="border-color: white;font-weight: bold;font-family: sans-serif;">Year</td>
<td style="border-color: white;font-weight: bold;font-family: sans-serif;"><input type="text" name="year" value="<%=year%>"></td>
</tr>
</table>
</form>
<table border="0" width="100%">
<tr ><td style="border-color: white;font-weight: bold;font-family: sans-serif;">
Forecast Summary for <%=getQuarterString(month)%>-year
</td></tr>
</table>
<table style='border-width: 1pt;border-right-width: 0pt;border-bottom-width: 0pt;border-style: solid;border-color: black;' border="1" width="100%" cellpadding='2' cellspacing='0'>
<tr bgcolor='#c0c0c0'>
<td class="td">Total Opportunities</td>
<td class="td">Total Closed</td>
<td class="td">Total Forecasted</td>
<td class="td">Total Commit</td>
<td class="td">Total Upside</td>
<td class="td">Total Longshot</td>
<td class="td">Total Prospect</td>
<td class="td">Total Inactive</td>
<td class="td">Total Lost</td>
</tr>
<tr>
<td class="td" align="center"><%=dealValues.length%></td>
<td class="td" align="center"><%=countClosed%></td>
<td class="td" align="center"><%=countForecast%></td>
<td class="td" align="center"><%=countCommit%></td>
<td class="td" align="center"><%=countUpside%></td>
<td class="td" align="center"><%=countLongshot%></td>
<td class="td" align="center"><%=countProspect%></td>
<td class="td" align="center"><%=countInactive%></td>
<td class="td" align="center"><%=countLost%></td>
</tr>
<tr bgcolor='#c0c0c0'>
<td class="td">Sum Opportunities</td>
<td class="td">Sum Closed</td>
<td class="td">Sum Forecasted</td>
<td class="td">Sum Commit</td>
<td class="td">Sum Upside</td>
<td class="td">Sum Longshot</td>
<td class="td">Sum Prospect</td>
<td class="td">Sum Inactive</td>
<td class="td">Sum Lost</td>
</tr>
<tr>
<td class="td" align="right">$<%=decimalFormat.format(sumOpportunities)%></td>
<td class="td" align="right">$<%=decimalFormat.format(sumClosed)%></td>
<td class="td" align="right">$<%=decimalFormat.format(sumForecast)%></td>
<td class="td" align="right">$<%=decimalFormat.format(sumCommit)%></td>
<td class="td" align="right">$<%=decimalFormat.format(sumUpside)%></td>
<td class="td" align="right">$<%=decimalFormat.format(sumLongshot)%></td>
<td class="td" align="right">$<%=decimalFormat.format(sumProspect)%></td>
<td class="td" align="right">$<%=decimalFormat.format(sumInactive)%></td>
<td class="td" align="right">$<%=decimalFormat.format(sumLost)%></td>
</tr>
</table>
<table border="0" height="20" width="100%" bgcolor="white">
<tr><td></td></tr>
</table>
<table border="0" width="100%">
<tr><td style="border-color: white;font-weight: bold;font-family: sans-serif;">
Forecasted Active Opportunities
</td></tr>
</table>
<table style='border-width: 1pt;border-right-width: 0pt;border-bottom-width: 0pt;border-style: solid;border-color: black;' border="1" width="100%" cellpadding='2' cellspacing='0'>
<tr bgcolor='#c0c0c0'>
<td class="td">Quarter</td>
<td class="td">Deal Name</td>
<td class="td" >Status</td>
<td class="td" >Stage</td>
<td class="td" >Region</td>
<td class="td" >Account</td>
<td class="td" >Industry</td>
<td class="td" >Projected Close Date</td>
<td class="td" >Est Customer Value</td>
<td class="td" >Forecast Amount</td>
</tr>
<%
for(int iz=0;iz<dealValues.length;iz++) {
dealValue = dealValues[iz];
Calendar calendar = Calendar.getInstance();
calendar.setTime(dealValue.getDate("projectedCloseDate"));
int status = Integer.valueOf(dealValue.getString("dealStatusId")).intValue();
if(status != 1) {
%>
<tr <%if(iz%2 != 0) {%> bgcolor="#E9E9E9" <% } %> >
<td class="td"><%=getQuarterString(calendar.get(Calendar.MONTH)+1)%>-<%=calendar.get(Calendar.YEAR)%></td>
<td class="td"><a href="<ofbiz:url>/dealDetail?dealId=<%=dealValue.getString("dealId")%></ofbiz:url>"><%=dealValue.getString("dealName")%></a></td>
<td class="td"><%=getFieldValue(dealStatus, "dealStatusId", dealValue.getString("dealStatusId"), "dealStatusName")%></td>
<td class="td"><%=getFieldValue(dealStage, "stageId", dealValue.getString("stageId"), "stageName")%></td>
<td class="td">[region]</td>
<td class="td"><%=getFieldValue(accountList, "accountId", dealValue.getString("accountId"), "accountName" )%></td>
<td class="td"><%=getFieldValue(accountList, "accountId", dealValue.getString("accountId"), "industry" )%></td>
<td class="td"><%=dealValue.getDate("projectedCloseDate")%></td>
<td class="td"> [ Est. Cust. Val. ]</td>
<td class="td" align="right">$<%=decimalFormat.format(dealValue.getDouble("amount").doubleValue())%></td>
</tr>
<% } %>
<% }%>
</table>
<%@ include file="/includes/footer.jsp" %>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -