📄 leadfrontpage.jsp
字号:
<%@ page import="org.ofbiz.base.util.*" %>
<%@ page import="org.ofbiz.entity.*" %>
<%@ page import="org.ofbiz.core.security.*" %>
<%@ page import="com.sourcetap.sfa.activity.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page import="com.sourcetap.sfa.ui.UIScreenSection" %>
<%@ page import="com.sourcetap.sfa.code.CodeHelper" %>
<%@page import="com.sourcetap.sfa.activity.CalendarUtil" %>
<%@ include file="/includes/header.jsp" %>
<%@ include file="/includes/errormsg.jsp"%>
<%@ include file="/includes/sfaSvgCheck.js" %>
<%@ include file="/includes/svgcheck.vbs" %>
<% String mimes = ""; %>
<SCRIPT LANGUAGE="JavaScript">
checkAndGetSVGViewer();
</SCRIPT>
<%
//get the date information
String day = "";
String lsMonth = "";
Calendar selectedDayCalendar = Calendar.getInstance();
int month = (selectedDayCalendar.get(Calendar.MONTH) + 1);
int year = selectedDayCalendar.get(Calendar.YEAR);
int iday = selectedDayCalendar.get(Calendar.DATE);
//if the user has selcted a day
//get the activities for that day
if ( request.getParameter("day") != null ) {
day = request.getParameter("day");
iday = Long.valueOf(day).intValue();
selectedDayCalendar.set(year, month -1, iday, 0, 0 );
}
// the user has selected a month then use that month.
if ( request.getParameter("month") != null ) {
lsMonth = request.getParameter("month");
month = Long.valueOf(lsMonth).intValue();
selectedDayCalendar.set(year, month -1, iday, 0, 0 );
}
%>
<%!
int daysSinceLastSale(String ownerId, int daysFromHire, GenericDelegator delegator) throws GenericEntityException{
//find last sale
Calendar lastSale = Calendar.getInstance();
HashMap fields = new HashMap();
fields.put("dealStatusId", "10"); //Sold
fields.put("ownerId", ownerId);
ArrayList order = new ArrayList();
order.add("actualCloseDate");
order.add("DESC");
List deals = delegator.findByAnd("Deal", fields, order);
if(deals.size() >= 1){
GenericValue details[] = (GenericValue[])deals.toArray(new GenericValue[0]);
GenericValue deal = details[deals.size()-1];
lastSale.setTime(deal.getDate("actualCloseDate"));
} else {
// No sales yet. Return the number of days since hire.
return daysFromHire;
}
//calc time since last sale
int returnInt = CalendarUtil.differenceBetweenDates(lastSale, Calendar.getInstance(), Calendar.DAY_OF_YEAR);
return returnInt;
}
double calculateYearlyQuota(String partyId, GenericDelegator delegator) throws GenericEntityException {
double yearlyQuotaAmount = 0.0;
HashMap fields = new HashMap();
fields.put("year", String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
fields.put("contactId", partyId);
List forecastL = delegator.findByAnd("Forecast", fields);
Iterator forecastI = forecastL.iterator();
while (forecastI.hasNext()) {
GenericValue forecastGV = (GenericValue)forecastI.next();
double quotaAmount = forecastGV.getDouble("quotaAmount")==null ?
0.0 : forecastGV.getDouble("quotaAmount").doubleValue();
yearlyQuotaAmount += quotaAmount;
}
return yearlyQuotaAmount;
}
double calculateYearlySales(String ownerId, GenericDelegator delegator) throws GenericEntityException {
double actual = 0.0;
Calendar start = Calendar.getInstance();
start.set(Calendar.MONTH, Calendar.JANUARY);
start.set(Calendar.DAY_OF_MONTH, 1);
Calendar end = Calendar.getInstance();
end.set(Calendar.MONTH, Calendar.DECEMBER);
end.set(Calendar.DAY_OF_MONTH, 1);
ArrayList list = new ArrayList();
list.add(new EntityExpr("dealStatusId", EntityOperator.EQUALS, "10")); // Sold
list.add(new EntityExpr("ownerId", EntityOperator.EQUALS, ownerId));
list.add(new EntityExpr("actualCloseDate", EntityOperator.LESS_THAN_EQUAL_TO, new java.sql.Date( end.getTime().getTime() )));
list.add(new EntityExpr("actualCloseDate", EntityOperator.GREATER_THAN_EQUAL_TO, new java.sql.Date( start.getTime().getTime() )));
List opps = delegator.findByAnd("Deal", list, null);
GenericValue oppDetails[] = (GenericValue[])opps.toArray(new GenericValue[0]);
GenericValue oppDetail;
for(int i=0;i<oppDetails.length;i++){
oppDetail = oppDetails[i];
actual = actual + oppDetail.getDouble("amount").doubleValue();
}
return actual;
}
double calculateYearlyExpenses(String ownerId, GenericDelegator delegator) throws GenericEntityException {
double actual = 0.0;
Calendar start = Calendar.getInstance();
start.set(Calendar.MONTH, Calendar.JANUARY);
start.set(Calendar.DAY_OF_MONTH, 1);
Calendar end = Calendar.getInstance();
end.set(Calendar.MONTH, Calendar.DECEMBER);
end.set(Calendar.DAY_OF_MONTH, 1);
ArrayList list = new ArrayList();
list.add(new EntityExpr("expenseOwnerId", EntityOperator.EQUALS, ownerId));
list.add(new EntityExpr("expenseDate", EntityOperator.LESS_THAN_EQUAL_TO, new java.sql.Date(end.getTime().getTime())));
list.add(new EntityExpr("expenseDate", EntityOperator.GREATER_THAN_EQUAL_TO, new java.sql.Date(start.getTime().getTime())));
List expenses = delegator.findByAnd("Expense", list, null);
GenericValue expenseDetails[] = (GenericValue[])expenses.toArray(new GenericValue[0]);
GenericValue expenseDetail;
for(int i=0;i<expenseDetails.length;i++){
expenseDetail = expenseDetails[i];
actual = actual + expenseDetail.getDouble("expenseAmount").doubleValue();
}
return actual;
}
Date getHireDate(String partyId, GenericDelegator delegator) throws GenericEntityException {
HashMap fields = new HashMap();
fields.put("contactId", partyId);
GenericValue contact = delegator.findByPrimaryKey("Contact", fields);
Date hireDate = contact.getDate("hireDate");
if ( hireDate == null )
hireDate = Calendar.getInstance().getTime();
return hireDate;
}
GenericValue[] getQuarterlyOpportunities(String ownerId, GenericDelegator delegator, int fyStartMonth) throws GenericEntityException {
Calendar cal = Calendar.getInstance();
ArrayList list = new ArrayList();
list.add(new EntityExpr("ownerId", EntityOperator.EQUALS, ownerId));
list.add(new EntityExpr("projectedCloseDate", EntityOperator.LESS_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMaximumQuarterDate((cal.get(Calendar.MONTH) + 1),cal.get(Calendar.YEAR), fyStartMonth).getTime())));
// list.add(new EntityExpr("projectedCloseDate", EntityOperator.GREATER_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMinimumQuarterDate((cal.get(Calendar.MONTH) + 1),cal.get(Calendar.YEAR), fyStartMonth).getTime())));
// list.add(new EntityExpr("isInForecast", EntityOperator.EQUALS, "1"));
// list.add(new EntityExpr("dealStatusId", EntityOperator.NOT_EQUAL, "10")); // Not sold
list.add(new EntityExpr("dealStatusId", EntityOperator.NOT_EQUAL, "70")); // Not lost
ArrayList order = new ArrayList();
order.add("projectedCloseDate");
List dealList = delegator.findByAnd("Deal", list, order);
return (GenericValue[])dealList.toArray(new GenericValue[0]);
}
GenericValue[] getDailyActivities(String ownerId, Calendar selectedDayCalendar, GenericDelegator delegator) throws GenericEntityException {
ArrayList list = new ArrayList();
list.add(new EntityExpr("activityOwnerId", EntityOperator.EQUALS, ownerId));
list.add(new EntityExpr("openDate", EntityOperator.EQUALS, new java.sql.Date(selectedDayCalendar.getTime().getTime())));
List activityList = delegator.findByAnd("Activity", list, null);
return (GenericValue[])activityList.toArray(new GenericValue[0]);
}
GenericValue[] getIncompleteActivities(String ownerId, GenericDelegator delegator) throws GenericEntityException {
ArrayList list = new ArrayList();
list.add(new EntityExpr("activityOwnerId", EntityOperator.EQUALS, ownerId));
list.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "30")); // Not declined
list.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "50")); // Not On Hold
list.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "60")); // Not Canceled
list.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "70")); // Not Done
List activityList = delegator.findByAnd("Activity", list, null);
return (GenericValue[])activityList.toArray(new GenericValue[0]);
}
%>
<%pageContext.setAttribute("PageName", "Main Page"); %>
<%String loginUrl = controlPath + "/checkLogin/" + UtilFormatOut.checkNull((String)request.getAttribute("_CURRENT_VIEW_"));%>
<% pageContext.setAttribute("PageName", "Main Page"); %>
<%
if(session.getAttribute("partyId") != null && userLogin != null ) {
int fyStartMonth = CalendarUtil.getFiscalYearStartMonth( delegator, userInfo );
double quota = calculateYearlyQuota(partyId, delegator);
double actual = calculateYearlySales(partyId, delegator);
double quotaPercent = ((actual == 0) || (actual == 0.0) ? 0.0 : ((actual / quota) * 100));
double expenses = calculateYearlyExpenses(partyId, delegator);
Calendar cal = Calendar.getInstance();
cal.setTime(getHireDate(partyId, delegator));
int daysFromHire = CalendarUtil.differenceBetweenDates(cal, Calendar.getInstance(), Calendar.DAY_OF_YEAR);
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/YYYY");
%>
<table width=100% class="freeFormSectionTitleTable">
<tr>
<td colspan=3>
<%=userInfo.getUserFullName()%>'s Dashboard
<td>
</tr>
</table>
<!-- Table to separate the top half of the screen from the bottom half -->
<table border=0>
<!-- Start top half of screen. -->
<tr>
<td valign="top">
<!-- Table to hold the columns of the top half of the screen -->
<table border=0>
<tr>
<!-- Cell for year-to-date and lifetime -->
<td valign="top">
<!-- Table to separate the year-to-date from the lifetime -->
<table border="0">
<tr>
<td>
<!-- Table for the year-to-date label -->
<table class="freeFormSectionTitleTable" width="100%">
<tr>
<td colspan=2>
Year to Date
</td>
</tr>
</table>
<!-- Table for the year-to-date info -->
<table class="freeFormSectionDisplayTable" width="100%">
<tr>
<td class="freeFormSectionLabelOptional">
Quota:
</td>
<td class="freeFormSectionField">
$<%=decimalFormat.format(quota)%>
</td>
</tr>
<tr>
<td class="freeFormSectionLabelOptional">
Total Sales:
</td>
<td class="freeFormSectionField">
$<%=decimalFormat.format(actual)%>
</td>
</tr>
<tr>
<td class="freeFormSectionLabelOptional">
Quota Percentage:
</td>
<td class="freeFormSectionField">
%<%=decimalFormat.format(quotaPercent)%>
</td>
</tr>
<tr>
<td class="freeFormSectionLabelOptional">
Expenses:
</td>
<td class="freeFormSectionField">
$<%=decimalFormat.format(expenses)%>
</td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -