public void extract(AdminListingActionForm actionForm, HttpServletRequest request)
throws Throwable {
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
OrderListingActionForm form = (OrderListingActionForm) actionForm;
AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
ActionMessages errors = validate(form);
if (errors.size() != 0) {
saveMessages(request, errors);
return;
}
Query query = null;
if (form.getSrPageNo().length() == 0) {
form.setSrPageNo("1");
}
String sql = "select orderHeader " +
"from OrderHeader orderHeader " +
"left join orderHeader.custAddress custAddress " +
"where orderHeader.siteDomain.site.siteId = :siteId ";
sql += "and orderHeader.orderDate between :orderCreatedOnStart and :orderCreatedOnEnd ";
if (form.getSrOrderNum().length() > 0) {
sql += "and orderHeader.orderNum like :orderNum ";
}
if (form.getSrCustFirstName().length() > 0) {
sql += "and custAddress.custFirstName like :custFirstName ";
}
if (form.getSrCustLastName().length() > 0) {
sql += "and custAddress.custLastName like :custLastName ";
}
if (form.getSrCustEmail().length() > 0) {
sql += "and orderHeader.custEmail like :custEmail ";
}
if (form.getSrCustCityName().length() > 0) {
sql += "and custAddress.custCityName like :custCityName ";
}
if (!form.getSrCustStateCode().equals("All")) {
sql += "and custAddress.custStateCode like :custStateCode ";
}
if (!form.getSrCustCountryCode().equals("All")) {
sql += "and custAddress.custCountryCode like :custCountryCode ";
}
if (!form.getSrOrderStatus().equals("All")) {
sql += "and orderHeader.orderStatus = :orderStatus ";
}
if (!form.getOrderAbundantLoc().equals("All")) {
sql += "and orderHeader.orderAbundantLoc = :orderAbundantLoc ";
}
sql += "order by orderHeader.orderDate desc ";
query = em.createQuery(sql);
query.setParameter("siteId", site.getSiteId());
Date date = null;
if (form.getSrOrderCreatedOnStart().length() > 0) {
date = Format.getDate(form.getSrOrderCreatedOnStart());
query.setParameter("orderCreatedOnStart", date);
}
else {
query.setParameter("orderCreatedOnStart", Format.LOWDATE);
}
if (form.getSrOrderCreatedOnEnd().length() > 0) {
date = Format.getDate(form.getSrOrderCreatedOnEnd());
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, 1);
query.setParameter("orderCreatedOnEnd", calendar.getTime());
}
else {
query.setParameter("orderCreatedOnEnd", Format.HIGHDATE);
}
if (form.getSrOrderNum().length() > 0) {
query.setParameter("orderNum", form.getSrOrderNum());
}
if (form.getSrCustFirstName().length() > 0) {
query.setParameter("custFirstName", form.getSrCustFirstName() + "%");
}
if (form.getSrCustLastName().length() > 0) {
query.setParameter("custLastName", form.getSrCustLastName() + "%");
}
if (form.getSrCustEmail().length() > 0) {
query.setParameter("custEmail", form.getSrCustEmail() + "%");
}
if (form.getSrCustCityName().length() > 0) {
query.setParameter("custCityName", form.getSrCustCityName());
}
if (!form.getSrCustStateCode().equals("All")) {
query.setParameter("custStateCode", form.getSrCustStateCode());
}
if (!form.getSrCustCountryCode().equals("All")) {
query.setParameter("custCountryCode", form.getSrCustCountryCode());
}
if (!form.getSrOrderStatus().equals("All")) {
query.setParameter("orderStatus", form.getSrOrderStatus());
}
if (!form.getOrderAbundantLoc().equals("All")) {
query.setParameter("orderAbundantLoc", form.getOrderAbundantLoc());
}
List<?> list = query.getResultList();
int pageNo = Integer.parseInt(form.getSrPageNo());
calcPage(adminBean, form, list, pageNo);
Vector<OrderListingDisplayForm> vector = new Vector<OrderListingDisplayForm>();
int startRecord = (pageNo - 1) * adminBean.getListingPageSize();
int endRecord = startRecord + adminBean.getListingPageSize();
for (int i = startRecord; i < list.size() && i < endRecord; i++) {
OrderHeader orderHeader = (OrderHeader) list.get(i);
OrderAddress orderAddress = orderHeader.getCustAddress();
OrderListingDisplayForm orderDisplay = new OrderListingDisplayForm();
orderDisplay.setOrderHeaderId(Format.getLong(orderHeader.getOrderHeaderId()));
orderDisplay.setOrderNum(orderHeader.getOrderNum());
orderDisplay.setCustFirstName(orderAddress.getCustFirstName());
orderDisplay.setCustLastName(orderAddress.getCustLastName());
orderDisplay.setCustEmail(orderHeader.getCustEmail());
orderDisplay.setCustCityName(orderAddress.getCustCityName());
orderDisplay.setCustStateCode(orderAddress.getCustStateCode());
orderDisplay.setCustCountryCode(orderAddress.getCustCountryCode());
orderDisplay.setOrderTotal(Format.getFloatObj(orderHeader.getOrderTotal()));
orderDisplay.setOrderStatus(orderHeader.getOrderStatus());
orderDisplay.setOrderDate(Format.getFullDatetime(orderHeader.getOrderDate()));
vector.add(orderDisplay);
}
form.setOrders(vector);
}