public String generateOrder() {

		FacesContext facesContext = FacesContext.getCurrentInstance();
		HttpSession session = (HttpSession) facesContext.getExternalContext()
				.getSession(false);

		// Session object holds current username
		String userId = (String) session.getAttribute("username");
		String role=(String)session.getAttribute("role");

		ProductService service = new ProductService();

		try {
			if(role.equalsIgnoreCase("customer"))
			this.customerId = userId;
			else
			this.customerId=null;
			service.updateStock(shoppingCart);
			String result[] = service.saveOrder(totalprice, customerId,
					paymentType, cardNo, expiryDate,expectedDate);
			this.receiptId=result[0];
			this.expectedDate=result[1];
           System.out.println(expectedDate);
			this.purchasedDate = new Date(System.currentTimeMillis());
			if(cardNo!=null)
			this.last5digit=cardNo.substring(cardNo.length()-5,cardNo.length());
			service.savePurchasedItems(shoppingCart,
					Integer.parseInt(receiptId));

		} catch (ConnectException e) {
			// TODO Auto-generated catch block
			this.errorMessage = e.getMessage();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			this.errorMessage = e.getMessage();
		}
		return "orderConfirmation";
	}