pos.showDialog("dialog/error/terminalclosed");
return;
}
Output output = pos.getOutput();
Input input = pos.getInput();
boolean lookup = false;
if (input.isFunctionSet("VOID")) {
lookup = true;
} else if (UtilValidate.isNotEmpty(input.value())) {
lookup = true;
}
if (lookup) {
GenericValue state = trans.getTerminalState();
Timestamp openDate = state.getTimestamp("openedDate");
String orderId = input.value();
GenericValue orderHeader = null;
try {
orderHeader = session.getDelegator().findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
if (orderHeader == null) {
input.clear();
pos.showDialog("dialog/error/ordernotfound");
return;
} else {
Timestamp orderDate = orderHeader.getTimestamp("orderDate");
if (orderDate.after(openDate)) {
LocalDispatcher dispatcher = session.getDispatcher();
Map<String, Object> returnResp = null;
try {
returnResp = dispatcher.runSync("quickReturnOrder", UtilMisc.<String, Object>toMap("orderId", orderId,
"returnHeaderTypeId", "CUSTOMER_RETURN", "userLogin", session.getUserLogin()));
} catch (GenericServiceException e) {
Debug.logError(e, module);
pos.showDialog("dialog/error/exception", e.getMessage());
pos.refresh();
return;
}
if (returnResp != null && ServiceUtil.isError(returnResp)) {
pos.showDialog("dialog/error/exception", ServiceUtil.getErrorMessage(returnResp));
pos.refresh();
return;
}
// todo print void receipt
trans.setTxAsReturn((String) returnResp.get("returnId"));
input.clear();
pos.showDialog("dialog/error/salevoided");
pos.refresh();
} else {
input.clear();
pos.showDialog("dialog/error/ordernotfound");
return;
}
}
} else {
input.setFunction("VOID");
output.print(UtilProperties.getMessage(PosTransaction.resource,"PosVoid",Locale.getDefault()));
}
}