String dataSource = Settings.getInstance().getSiteInfo(CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();
try {
HttpSession session = request.getSession(true);
SaleFacadeHome salesFacadeHome = (SaleFacadeHome) CVUtility.getHomeObject("com.centraview.sale.salefacade.SaleFacadeHome", "SaleFacade");
SaleFacade remote = salesFacadeHome.create();
remote.setDataSource(dataSource);
String typeofoperation = SaleConstantKeys.ADD;
if (request.getParameter(SaleConstantKeys.TYPEOFOPERATION) != null) {
typeofoperation = request.getParameter(SaleConstantKeys.TYPEOFOPERATION);
} else if (request.getAttribute(SaleConstantKeys.TYPEOFOPERATION) != null) {
typeofoperation = (String) request.getAttribute(SaleConstantKeys.TYPEOFOPERATION);
}
OpportunityForm opportunityForm = (OpportunityForm) form;
OpportunityVO opportunityVO = new OpportunityVO();
ActivityVO activityVO = new ActivityVO();
activityVO.setStatus(Integer.parseInt(opportunityForm.getStatusid()));
activityVO.setTitle(opportunityForm.getTitle());
activityVO.setActivityDetails(opportunityForm.getDescription());
int ownerId = ((UserObject) session.getAttribute("userobject")).getIndividualID();
activityVO.setCreatedBy(ownerId);
activityVO.setOwner(ownerId);
activityVO.setActivityID(Integer.parseInt(opportunityForm.getActivityid()));
opportunityVO.setActivityVO(activityVO);
opportunityVO.setTitle(opportunityForm.getTitle());
opportunityVO.setDescription(opportunityForm.getDescription());
opportunityVO.setEntityID(Integer.parseInt(opportunityForm.getEntityid()));
opportunityVO.setIndividualID(Integer.parseInt(opportunityForm.getIndividualid()));
opportunityVO.setOpportunityTypeID(Integer.parseInt(opportunityForm.getOpportunitytypeid()));
opportunityVO.setStatusID(Integer.parseInt(opportunityForm.getStatusid()));
opportunityVO.setStageID(Integer.parseInt(opportunityForm.getStageid()));
String Totalamount = opportunityForm.getTotalamount();
if (Totalamount != null) {
Totalamount = Totalamount.replaceAll(" ", "");//remove empty spaces
NumberFormat nf = NumberFormat.getInstance();
Totalamount = nf.parse(Totalamount).toString();
}
opportunityVO.setActualAmount(Float.parseFloat(Totalamount));
opportunityVO.setProbability(Integer.parseInt(opportunityForm.getProbabilityid()));
opportunityVO.setForecastedAmount(Float.parseFloat(Totalamount));
opportunityVO.setSourceID(Integer.parseInt(opportunityForm.getSourceid()));
opportunityVO.setSource(opportunityForm.getSourcename());
opportunityVO.setAcctMgr(Integer.parseInt(opportunityForm.getAcctmgrid()));
opportunityVO.setAcctTeam(Integer.parseInt(opportunityForm.getAcctteamid()));
if ((opportunityForm.getEstimatedclosemonth() != null) && (opportunityForm.getEstimatedcloseday() != null)
&& (opportunityForm.getEstimatedcloseyear() != null)) {
String estimatedclosemonth = opportunityForm.getEstimatedclosemonth();
String estimatedcloseday = opportunityForm.getEstimatedcloseday();
String estimatedcloseyear = opportunityForm.getEstimatedcloseyear();
try {
int estimatedclosemonth1 = Integer.parseInt(estimatedclosemonth);
int estimatedcloseday1 = Integer.parseInt(estimatedcloseday);
int estimatedcloseyear1 = Integer.parseInt(estimatedcloseyear);
Calendar estimatedClose = new GregorianCalendar();
estimatedClose.set(estimatedcloseyear1, estimatedclosemonth1 - 1, estimatedcloseday1);
opportunityVO.setEstimatedClose(new Timestamp(estimatedClose.getTimeInMillis()));
} catch (NumberFormatException nfe) {
logger.info("[execute]: blank date fields");
} catch (Exception e) {
logger.error("[execute]: Exception");
}
}
if (typeofoperation.equals(SaleConstantKeys.ADD)) {
remote.addOpportunity(ownerId, opportunityVO);
} else if (typeofoperation.equals(SaleConstantKeys.EDIT)) {
String opportunityid = request.getParameter("opportunityid");
if ((opportunityForm.getActualclosemonth() != null) && (opportunityForm.getActualcloseday() != null)
&& (opportunityForm.getActualcloseyear() != null)) {
String actualclosemonth = opportunityForm.getActualclosemonth();
String actualcloseday = opportunityForm.getActualcloseday();
String actualcloseyear = opportunityForm.getActualcloseyear();
try {
int actualclosemonth1 = Integer.parseInt(actualclosemonth);
int actualcloseday1 = Integer.parseInt(actualcloseday);
int actualcloseyear1 = Integer.parseInt(actualcloseyear);
Calendar actualClose = new GregorianCalendar(actualcloseyear1, actualclosemonth1 - 1, actualcloseday1);
opportunityVO.setActualclose(new Timestamp(actualClose.getTimeInMillis()));
} catch (NumberFormatException nfe) {
logger.info("[execute]: blank date fields");
} catch (Exception e) {
logger.error("[execute]: Exception", e);
}
}
opportunityVO.setOpportunityID(Integer.parseInt(opportunityid));
request.setAttribute("recordID", new Integer(opportunityVO.getOpportunityID()).toString());
request.setAttribute("recordName", opportunityVO.getTitle());
request.setAttribute("OPPORTUNITYID", new Integer(opportunityVO.getOpportunityID()));
remote.updateOpportunity(ownerId, opportunityVO);
}
request.setAttribute(SaleConstantKeys.CURRENTTAB, SaleConstantKeys.DETAIL);
request.setAttribute(SaleConstantKeys.TYPEOFOPERATION, SaleConstantKeys.ADD);
request.setAttribute(SaleConstantKeys.WINDOWID, "1");
if (request.getParameter("closeornew").equals("close")) {