📄 forecast.jsp
字号:
boolean opportunityHasProducts = opportunityHasProductsString.equals("yes");
double dealTotal = 0.0;
ArrayList subRoles = null;
String view = "individual";
if(request.getParameter("view") != null){
view = request.getParameter("view");
if(view.equalsIgnoreCase("role")){
subRoles = (ArrayList)RoleHelper.getSubordinateRolesForParty((String)session.getAttribute("partyId"), (String)session.getAttribute("roleId"), delegator);
Debug.logVerbose("sub-roles = " + subRoles.toString(), "forecast");
}
}
int month = (request.getParameter("month") == null ? (Calendar.getInstance().get(Calendar.MONTH) + 1) : Integer.parseInt(request.getParameter("month")));
int year = (request.getParameter("year") == null ? Calendar.getInstance().get(Calendar.YEAR) : Integer.parseInt(request.getParameter("year")));
String quarterString = CalendarUtil.getQuarterString(month, fyStartMonth);
int quarterMonthNumbers[] = CalendarUtil.getQuarterMonthNumbers(month, fyStartMonth);
String quarterMonthNames[] = CalendarUtil.getQuarterMonthNames(month, fyStartMonth);
// Get Forecasts
ArrayList forecastFindList = new ArrayList();
forecastFindList.add(new EntityExpr("contactId", EntityOperator.EQUALS, userInfo.getPartyId()));
forecastFindList.add(new EntityExpr("month", EntityOperator.GREATER_THAN_EQUAL_TO, new Long(quarterMonthNumbers[0])));
forecastFindList.add(new EntityExpr("month", EntityOperator.LESS_THAN_EQUAL_TO, new Long(quarterMonthNumbers[2])));
forecastFindList.add(new EntityExpr("year", EntityOperator.EQUALS, new Long(year)));
List forecastList = delegator.findByAnd("Forecast", forecastFindList, UtilMisc.toList("year", "month"));
// Make sure there are 3 forecast records. If not, create them in the list,
// but don't store them yet.
for (int monthNdx = 0; monthNdx < 3; monthNdx++) {
boolean foundForecast = false;
// Look through the forecasts and see if one was found for this month.
Iterator forecastI = forecastList.iterator();
while (forecastI.hasNext() && !foundForecast) {
GenericValue forecastGV = (GenericValue) forecastI.next();
long forecastMonth = forecastGV.getLong("month").longValue();
if (forecastMonth == quarterMonthNumbers[monthNdx]) {
foundForecast = true;
}
}
if (!foundForecast) {
// Need to create a new forecast.
GenericValue forecastGV = new GenericValue(delegator.getModelEntity("Forecast"));
forecastGV.setDelegator(delegator);
forecastGV.set("contactId", userInfo.getPartyId());
forecastGV.set("year", new Long(year));
forecastGV.set("month", new Long(quarterMonthNumbers[monthNdx]));
forecastGV.set("quotaAmount", new Double(0));
forecastList.add(forecastGV);
}
}
boolean quotaSaved = false;
if (request.getParameter("saveQuotaButton") != null && request.getParameter("saveQuotaButton").equals("Save")) {
// Update all 3 forecast records.
Iterator forecastI = forecastList.iterator();
while (forecastI.hasNext()) {
GenericValue forecastGV = (GenericValue) forecastI.next();
long forecastMonth = forecastGV.getLong("month").longValue();
Double quotaAmount;
String parameterName = "quota" + String.valueOf(forecastMonth - quarterMonthNumbers[0]);
if (request.getParameter(parameterName) != null) {
String quotaAmountString = request.getParameter(parameterName);
DecimalFormat decimalParser = new DecimalFormat();
ParsePosition parsePosition = new ParsePosition(0);
Number parsedNumber = decimalParser.parse(quotaAmountString, parsePosition);
//out.write("parsed value: " + String.valueOf(parsedNumber) + "<BR>");
quotaAmount = new Double(String.valueOf(parsedNumber));
} else {
quotaAmount = new Double(0);
}
if (forecastGV.get("forecastId")==null) forecastGV.set("forecastId", GenericReplicator.getNextSeqId("Forecast", delegator));
forecastGV.set("quotaAmount", quotaAmount);
Timestamp now = new Timestamp(new java.util.Date().getTime());
if (forecastGV.get("createdBy")==null ) forecastGV.set("createdBy", userInfo.getPartyId());
if (forecastGV.get("createdDate")==null ) forecastGV.set("createdDate", now);
forecastGV.set("modifiedBy", userInfo.getPartyId());
forecastGV.set("modifiedDate", now);
}
delegator.storeAll(forecastList);
quotaSaved = true;
}
//get deail/forecast details
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, month - 1);
cal.set(Calendar.YEAR, year);
//for a role, find every oportunity under this role. Each opportunity should be owned by the role-contact. the opportunity should be in-forecast, and within the current quarter.
DynamicViewEntity dve = EntityHelper.createDynamicViewEntity( delegator, "Deal");
dve.addMemberEntity("EntityAccess", "EntityAccess");
dve.addViewLink("Deal", "EntityAccess", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("dealId", "entityId")));
dve.addMemberEntity("TeamMember", "TeamMember");
dve.addViewLink("EntityAccess", "TeamMember", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("partyId", "teamId")));
dve.addAlias("TeamMember", "teamOwner", null, null, null, null, null);
dve.addAlias("TeamMember", "partyId", null, null, null, null, null);
dve.addAlias("EntityAccess", "entity", null, null, null, null, null);
dve.addAlias("EntityAccess", "partyEntityType", null, null, null, null, null);
ArrayList list = new ArrayList();
list.add(new EntityExpr("teamOwner", EntityOperator.EQUALS, "Y"));
list.add(new EntityExpr("projectedCloseDate", EntityOperator.LESS_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMaximumQuarterDate(month, year, fyStartMonth).getTime())));
list.add(new EntityExpr("projectedCloseDate", EntityOperator.GREATER_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMinimumQuarterDate(month, year, fyStartMonth).getTime())));
list.add(new EntityExpr("isInForecast", EntityOperator.EQUALS, "Y"));
list.add(new EntityExpr("entity", EntityOperator.EQUALS, "Deal"));
list.add(new EntityExpr("partyEntityType", EntityOperator.EQUALS, "Team"));
if(view.equals("individual")){
list.add(new EntityExpr("ownerId", EntityOperator.EQUALS, (String)session.getAttribute("partyId")));
list.add(new EntityExpr("partyId", EntityOperator.EQUALS, (String)session.getAttribute("partyId")));
}
EntityCondition condition = new EntityConditionList(list, EntityOperator.AND);
if(view.equals("role")){
dve.addMemberEntity("Contact", "Contact");
dve.addViewLink("TeamMember", "Contact", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("partyId", "contactId")));
dve.addAlias("Contact", "roleId", null, null, null, null, null);
ArrayList list2 = new ArrayList();
for(int i=0;i<subRoles.size();i++){
list2.add(new EntityExpr("roleId", EntityOperator.EQUALS, subRoles.get(i)));
}
EntityCondition condition2 = new EntityConditionList( list2, EntityOperator.OR );
condition = new EntityConditionList( UtilMisc.toList( condition, condition2), EntityOperator.AND );
}
List dealList = EntityHelper.findByCondition(delegator, dve, condition, UtilMisc.toList("projectedCloseDate"));
GenericValue dealValues[] = (GenericValue[])dealList.toArray(new GenericValue[0]);
dve = EntityHelper.createDynamicViewEntity( delegator, "OpportunityProduct");
dve.addMemberEntity("Deal", "Deal");
dve.addViewLink("OpportunityProduct", "Deal", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("dealId", "dealId")));
dve.addMemberEntity("EntityAccess", "EntityAccess");
dve.addViewLink("Deal", "EntityAccess", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("dealId", "entityId")));
dve.addMemberEntity("TeamMember", "TeamMember");
dve.addViewLink("EntityAccess", "TeamMember", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("partyId", "teamId")));
dve.addMemberEntity("Contact", "Contact");
dve.addAlias("TeamMember", "teamOwner", null, null, null, null, null);
dve.addAlias("TeamMember", "partyId", null, null, null, null, null);
dve.addAlias("EntityAccess", "entity", null, null, null, null, null);
dve.addAlias("EntityAccess", "partyEntityType", null, null, null, null, null);
dve.addAlias("Deal", "projectedCloseDate", null, null, null, null, null);
dve.addAlias("Deal", "useProductsForAmount", null, null, null, null, null);
dve.addAlias("Deal", "isInForecast", null, null, null, null, null);
list = new ArrayList();
list.add(new EntityExpr("teamOwner", EntityOperator.EQUALS, "Y"));
list.add(new EntityExpr("projectedCloseDate", EntityOperator.LESS_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMaximumQuarterDate(month, year, fyStartMonth).getTime())));
list.add(new EntityExpr("projectedCloseDate", EntityOperator.GREATER_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMinimumQuarterDate(month, year, fyStartMonth).getTime())));
list.add(new EntityExpr("isInForecast", EntityOperator.EQUALS, "Y"));
list.add(new EntityExpr("useProductsForAmount", EntityOperator.EQUALS, "Y"));
list.add(new EntityExpr("entity", EntityOperator.EQUALS, "Deal"));
list.add(new EntityExpr("partyEntityType", EntityOperator.EQUALS, "Team"));
if(view.equals("individual")){
list.add(new EntityExpr("partyId", EntityOperator.EQUALS, (String)session.getAttribute("partyId")));
}
condition = new EntityConditionList(list, EntityOperator.AND);
if(view.equals("role")){
dve.addMemberEntity("Contact", "Contact");
dve.addViewLink("TeamMember", "Contact", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("partyId", "contactId")));
dve.addAlias("Contact", "roleId", null, null, null, null, null);
ArrayList list2 = new ArrayList();
for(int i=0;i<subRoles.size();i++){
list2.add(new EntityExpr("roleId", EntityOperator.EQUALS, subRoles.get(i)));
}
EntityCondition condition2 = new EntityConditionList( list2, EntityOperator.OR );
condition = new EntityConditionList( UtilMisc.toList( condition, condition2), EntityOperator.AND );
}
List opportunityProductList = null;
if ( opportunityHasProducts )
{
opportunityProductList = EntityHelper.findByCondition(delegator, dve, condition, null);
}
HashMap dealStatusFields = new HashMap();
dealStatusFields.put("codeTypeId", "OPPORTUNITY_STATUS");
ArrayList dealStatusOrderBy = new ArrayList();
dealStatusOrderBy.add("codeTypeId");
List dealStatus = delegator.findByAnd("Code", dealStatusFields, dealStatusOrderBy);
List dealStage = delegator.findAll("DealStage", null);
//Accounts
HashMap accountFields = new HashMap();
accountFields.put("accountOwnerId", session.getAttribute("partyId"));
List accountList = delegator.findByAnd("Account", accountFields);
HashMap accountMap = new HashMap();
if ( accountList != null )
{
for ( int ii=0; ii < accountList.size(); ii++ )
{
GenericValue acct = (GenericValue) accountList.get(ii);
String acctId = acct.getString("accountId");
accountMap.put( acctId, acct );
}
}
String requestMonth = "";
if(request.getParameter("month") != null){
requestMonth = request.getParameter("month");
} else {
requestMonth = String.valueOf(Calendar.getInstance().get(Calendar.MONTH) + 1);
}
String requestQuarter = "Q1";
try {
requestQuarter = CalendarUtil.getQuarterString(Integer.valueOf(requestMonth).intValue(), fyStartMonth);
}
catch ( Exception qe )
{
Debug.logError("invalid number format", "forecast.jsp");
}
%>
<form method="post" action="<ofbiz:url>/forecasts</ofbiz:url>" name="MonthForm">
<table width=100% class="freeFormSectionTitleTable">
<tr>
<td>
<table class="freeFormSectionTitleTable">
<tr>
<td>
Q1<input type="radio" name="month" value="<%=fyStartMonth%>" onclick="document.MonthForm.submit();" <%if(requestQuarter.equals("Q1")){%> checked <%}%>>
</td>
<td>
Q2<input type="radio" name="month" value="<%=fyStartMonth == 9 ? 12 : ((fyStartMonth + 3) % 12)%>" onclick="document.MonthForm.submit();" <%if(requestQuarter.equals("Q2")){%> checked <%}%>>
</td>
<td>
Q3<input type="radio" name="month" value="<%=fyStartMonth == 6 ? 12 : ((fyStartMonth + 6) % 12)%>" onclick="document.MonthForm.submit();" <%if(requestQuarter.equals("Q3")){%> checked <%}%>>
</td>
<td>
Q4<input type="radio" name="month" value="<%=fyStartMonth == 3 ? 12 : ((fyStartMonth + 9) % 12)%>" onclick="document.MonthForm.submit();" <%if(requestQuarter.equals("Q4")){%> checked <%}%>>
</td>
<td>
Year:
</td>
<td>
<input maxlength=4 size=4 type="text" name="year" value="<%=year%>" class="freeFormSectionInputBox" onblur="document.MonthForm.submit();">
</td>
</tr>
</table>
</td>
<td ALIGN="right" width="*">
Individual <input type="radio" name="view" value="individual" onclick='javascrip:document.forms("MonthForm").submit();' <%if(view.equals("individual")){%> checked <%}%>>
Rollup <input type="radio" name="view" value="role" onclick='javascrip:document.forms("MonthForm").submit();' <%if(view.equals("role")){%> checked <%}%>>
<input type=hidden name=month value=<%=requestMonth%>>
</td>
</tr>
</table>
<table width="100%" class="freeFormSectionTitleTable">
<tr>
<td>
<%=userName%>'s
<% if(view.equals("role")) { %>
Rollup
<% } else { %>
Individual
<% } %>
Forecast Summary for <%=quarterString%>-<%=year%>
</td>
</tr>
</table>
<%
List productsList = null;
GenericValue productValues[] = null;
GenericValue productValue = null;
List productCategoryList = null;
GenericValue productCategoryValues[] = null;
GenericValue productCategoryValue = null;
if ( opportunityHasProducts )
{
//Get a list of all products for column rows.
productsList = ProductHelper.getProducts(delegator, userInfo);
productValues = (GenericValue[])productsList.toArray(new GenericValue[0]);
productValue = null;
productCategoryList = ProductHelper.getProductCategories(delegator, userInfo);
productCategoryValues = (GenericValue[])productCategoryList.toArray(new GenericValue[0]);
productCategoryValue = null;
}
%>
<table class="tabularSectionDisplayTable" width="*">
<tr class="tabularSectionLabel">
<td>Status</td>
<td># of Opps</td>
<td>Total</td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -