HttpSession session = request.getSession();
UserObject userObject = (UserObject) session.getAttribute("userobject");
int individualID =userObject.getIndividualID();
ProposalListForm proposallistform = (ProposalListForm) form;
OrderForm of = new OrderForm();
int proposalID = 0;
try {
proposalID = Integer.parseInt(request.getParameter("eventid"));
} catch (Exception ex) {
proposalID = Integer.parseInt(proposallistform.getProposalid());
}
String entityid = request.getParameter("entityID");
int entityID = 0;
if (entityid != null) {
entityID = Integer.parseInt(entityid);
} else {
entityID = proposallistform.getEntityID();
}
AccountFacadeHome afh = (AccountFacadeHome) CVUtility.getHomeObject("com.centraview.account.accountfacade.AccountFacadeHome", "AccountFacade");
SaleFacadeHome sfh = (SaleFacadeHome) CVUtility.getHomeObject("com.centraview.sale.salefacade.SaleFacadeHome","SaleFacade");
try {
SaleFacade saleRemote =(SaleFacade) sfh.create();
saleRemote.setDataSource(dataSource);
AccountFacade orderRemote = (AccountFacade) afh.create();
orderRemote.setDataSource(dataSource);
HashMap hm = (HashMap) saleRemote.viewProposal(individualID, proposalID , proposallistform);
ItemLines itemLines = (ItemLines)hm.get("itemLines");
proposallistform = (ProposalListForm) hm.get("dyna");
com.centraview.account.common.ItemLines accItemLines = new com.centraview.account.common.ItemLines();
if (itemLines != null) {
Set s = itemLines.keySet();
Iterator itr = s.iterator();
int id = 0;
int counter = 0;
while (itr.hasNext()) {
ItemElement ie2 = (ItemElement)itemLines.get(itr.next());
IntMember LineId = (IntMember)ie2.get("LineId");
IntMember ItemId = (IntMember)ie2.get("ItemId");
StringMember SKU = (StringMember)ie2.get("SKU");
StringMember Description = (StringMember)ie2.get("Description");
IntMember Quantity = (IntMember)ie2.get("Quantity");
FloatMember PriceEach = (FloatMember)ie2.get("Price");
FloatMember PriceExtended = (FloatMember)ie2.get("PriceExtended");
FloatMember taxAmount = (FloatMember)ie2.get("TaxAmount");
com.centraview.account.common.ItemElement ie = new com.centraview.account.common.ItemElement(counter);
ie.put("LineId", LineId);
ie.put("ItemId", ItemId);
ie.put("SKU", SKU);
ie.put("Description", Description);
ie.put("Quantity", Quantity);
ie.put("Price", PriceEach);
ie.put("PriceExtended", PriceExtended);
ie.put("TaxAmount", taxAmount);
accItemLines.put(new Integer(counter), ie);
counter++;
}
}
of.setItemLines(accItemLines);
int billingID = 0;
int shippingID = 0;
if (proposallistform.getBillingaddressid() != null && !proposallistform.getBillingaddressid().equals("")) {
billingID = Integer.parseInt(proposallistform.getBillingaddressid());
}
if (proposallistform.getShippingaddressid() != null && !proposallistform.getShippingaddressid().equals("")) {
shippingID = Integer.parseInt(proposallistform.getShippingaddressid());
}
of.setShipToAddIdValue(shippingID);
of.setBillToAddIdValue(billingID);
of.setCustomerIdValue(entityID);
of.setOrderDate(new java.sql.Date(System.currentTimeMillis()));
of.setJurisdictionID(new Integer(proposallistform.getJurisdictionID()));
of.setNotes(proposallistform.getProposal() + "-" + proposallistform.getProdescription());
GlobalMasterLists gml = GlobalMasterLists.getGlobalMasterLists(dataSource);
Vector statusVector = null;
statusVector = (Vector)gml.get("AccountingStatus");
for (int i = 0; i < statusVector.size(); i++) {
if (((DDNameValue) statusVector.get(i)).getName().equals("Pending")) {
of.setStatusIdValue(((DDNameValue) statusVector.get(i)).getId());
break;
}
}
// hardcoded to today() as orderDate will be today when order is created
// set after calling convert.. as that method sets date from day month yr var.s
// and that date will be null
OrderForm createdForm = orderRemote.createOrder(of, individualID);
int orderID = createdForm.getOrderIdValue();
request.setAttribute("GeneratedOrderId",new Integer(orderID));
if (orderID != 0) {
saleRemote.setOrderIsGenerated(true,proposalID,orderID);
}