SaleFacadeHome mfh = (SaleFacadeHome)CVUtility.getHomeObject(
"com.centraview.sale.salefacade.SaleFacadeHome", "SaleFacade");
try {
SaleFacade remote = mfh.create();
remote.setDataSource(dataSource);
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());
activityVO.setCreatedBy(ownerId);
activityVO.setOwner(ownerId);
opportunityVO.setActivityVO(activityVO);
opportunityVO.setTitle(opportunityForm.getTitle());
opportunityVO.setDescription(opportunityForm.getDescription());
int entityIdInt = 0;
String entityId = opportunityForm.getEntityid();
try {
entityIdInt = Integer.parseInt(entityId);
} catch (NumberFormatException nfe) {}
if (entityIdInt <= 0) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
"error.general.requiredField", "Entity"));
}
opportunityVO.setEntityID(entityIdInt);
if (!opportunityForm.getIndividualid().trim().equals("")) {
opportunityVO.setIndividualID(Integer.parseInt(opportunityForm.getIndividualid()));
}
opportunityVO.setOpportunityTypeID(Integer.parseInt(opportunityForm.getOpportunitytypeid()));
opportunityVO.setStatusID(Integer.parseInt(opportunityForm.getStatusid()));
opportunityVO.setStageID(Integer.parseInt(opportunityForm.getStageid()));
if (!opportunityForm.getTotalamount().trim().equals("")) {
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));
}
String ForecastedAmount = opportunityForm.getForecastedamount();
if (ForecastedAmount != null) {
ForecastedAmount = ForecastedAmount.replaceAll(" ", "");// remove empty
// spaces
NumberFormat nf = NumberFormat.getInstance();
ForecastedAmount = nf.parse(ForecastedAmount).toString();
}
opportunityVO.setForecastedAmount(Float.parseFloat(ForecastedAmount));
opportunityVO.setProbability(Integer.parseInt(opportunityForm.getProbabilityid()));
if ((opportunityForm.getSourceid() != null)
&& ((opportunityForm.getSourceid()).length() > 0)) {
opportunityVO.setSourceID(Integer.parseInt(opportunityForm.getSourceid()));
}
opportunityVO.setSource(opportunityForm.getSourcename());
if (opportunityForm.getAcctmgrid() != null
&& !opportunityForm.getAcctmgrid().trim().equals("")
&& !opportunityForm.getAcctmgrid().trim().equals("0")) {
opportunityVO.setAcctMgr(Integer.parseInt(opportunityForm.getAcctmgrid()));
} else {
opportunityVO.setAcctMgr(ownerId);
}
if (!opportunityForm.getAcctteamid().trim().equals("")) {
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 {
Timestamp eClose = DateUtility.createTimestamp(estimatedcloseyear, estimatedclosemonth,
estimatedcloseday);
opportunityVO.setEstimatedClose(eClose);
} catch (Exception e) {
logger.error("[execute]: Exception", e);
}
}
if (!allErrors.isEmpty()) {
this.saveErrors(request, allErrors);
return mapping.findForward(".view.sales.new_opportunity");
}
int recordID = remote.addOpportunity(ownerId, opportunityVO);
rowID = recordID;
request.setAttribute(SaleConstantKeys.CURRENTTAB, SaleConstantKeys.DETAIL);
request.setAttribute(SaleConstantKeys.TYPEOFOPERATION, SaleConstantKeys.ADD);
request.setAttribute(SaleConstantKeys.WINDOWID, "1");