int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
int quarterNumbers[] = CalendarUtil.getQuarterMonthNumbers(month, fyStartMonth);
ArrayList list = new ArrayList();
list.add(new EntityExpr("ownerId", EntityOperator.EQUALS, userInfo.getPartyId()));
list.add(new EntityExpr("dealStatusId", EntityOperator.EQUALS, "10"));
list.add(new EntityExpr("actualCloseDate", 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("actualCloseDate", EntityOperator.GREATER_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMinimumQuarterDate(cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR), fyStartMonth).getTime())));
ArrayList order = new ArrayList();
order.add("actualCloseDate");
java.util.List dealList = delegator.findByAnd("Deal", list, order);
GenericValue dealValues[] = (GenericValue[])dealList.toArray(new GenericValue[0]);
GenericValue dealValue = null;
String months[] = CalendarUtil.getQuarterMonthNames(cal.get(Calendar.MONTH) + 1, fyStartMonth);
for(int iz=0;iz<months.length;iz++){
xAxisLabels.add((String)months[iz]);
}
xAxisTitle = "Month";
yAxisTitle = "Sales";
legendLabels.add("Pipeline for Quarter");
for(int iz=0;iz<dealValues.length;iz++) {
dealValue = dealValues[iz];
Calendar calendar = Calendar.getInstance();
calendar.setTime(dealValue.getDate("actualCloseDate"));
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[0] && calendar.get(Calendar.YEAR)==year){
data[0] = data[0] + dealValue.getDouble("amount").doubleValue();
}
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[1] && calendar.get(Calendar.YEAR)==year){
data[1] = data[1] + dealValue.getDouble("amount").doubleValue();
}
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[2] && calendar.get(Calendar.YEAR)==year){
data[2] = data[2] + dealValue.getDouble("amount").doubleValue();
}
}
try {
BarChart barChart = new BarChart(
new SingleDataSet(
data,
(String[])legendLabels.toArray(new String[0]),
(String[])xAxisLabels.toArray(new String[0]),
paints,
xAxisTitle,
yAxisTitle ),
false, properties, axisProperties, width, height );
response.reset();
response.setContentType("image/jpeg");
barChart.exportJPG( response.getOutputStream(), 1.0f);
response.getOutputStream().flush();
} catch( Throwable throwable ) { throwable.printStackTrace();
}
}
if(request.getParameter("report").equals("leadsForQuarter")){
double data[] = new double[3];
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
int quarterNumbers[] = CalendarUtil.getQuarterMonthNumbers(month, fyStartMonth);
ArrayList list = new ArrayList();
list.add(new EntityExpr("leadOwnerId", EntityOperator.EQUALS, userInfo.getPartyId()));
list.add(new EntityExpr("statusId", EntityOperator.EQUALS, "50"));
list.add(new EntityExpr("convertedDate", 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("convertedDate", EntityOperator.GREATER_THAN_EQUAL_TO, new java.sql.Date( CalendarUtil.getMinimumQuarterDate(cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR), fyStartMonth).getTime())));
ArrayList order = new ArrayList();
order.add("convertedDate");
java.util.List dealList = delegator.findByAnd("Lead", list, order);
GenericValue leadValues[] = (GenericValue[])dealList.toArray(new GenericValue[0]);
GenericValue leadValue = null;
String months[] = CalendarUtil.getQuarterMonthNames(cal.get(Calendar.MONTH) + 1, fyStartMonth);
for(int iz=0;iz<months.length;iz++){
xAxisLabels.add((String)months[iz]);
}
xAxisTitle = "Month";
yAxisTitle = "Leads";
legendLabels.add("Leads for Quarter");
for(int iz=0;iz<leadValues.length;iz++) {
leadValue = leadValues[iz];
Calendar calendar = Calendar.getInstance();
calendar.setTime(leadValue.getTimestamp("convertedDate"));
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[0] && calendar.get(Calendar.YEAR)==year){
data[0] = data[0] + 1;
}
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[1] && calendar.get(Calendar.YEAR)==year){
data[1] = data[1] + 1;
}
if((calendar.get(Calendar.MONTH)+1)==quarterNumbers[2] && calendar.get(Calendar.YEAR)==year){
data[2] = data[2] + 1;
}
}
axisProperties.setYAxisUseDollarSigns(false);
axisProperties.setYAxisRoundValuesToNearest(0);
// axisProperties.setXAxisVerticalScaleFlag(true);
try {
BarChart barChart = new BarChart(
new SingleDataSet(
data,
(String[])legendLabels.toArray(new String[0]),
(String[])xAxisLabels.toArray(new String[0]),
paints,
xAxisTitle,
yAxisTitle ),
false, properties, axisProperties, width, height );
response.reset();
response.setContentType("image/jpeg");
barChart.exportJPG( response.getOutputStream(), 1.0f);
response.getOutputStream().flush();
} catch( Throwable throwable ) { throwable.printStackTrace();
}
}
if(request.getParameter("report").equals("forecastedForQuarter")){
double data[] = new double[3];
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
int quarterNumbers[] = CalendarUtil.getQuarterMonthNumbers(month, fyStartMonth);
ArrayList list = new ArrayList();
list.add(new EntityExpr("ownerId", EntityOperator.EQUALS, userInfo.getPartyId()));
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())));
ArrayList order = new ArrayList();
order.add("projectedCloseDate");
java.util.List dealList = delegator.findByAnd("Deal", list, order);