ShipHeader shipHeader = null;
if (!Format.isNullOrEmpty(shipHeaderId)) {
shipHeader = (ShipHeader) em.find(ShipHeader.class, Format.getLong(form.getShipHeaderId()));
}
ShipEngine shipEngine = null;
if (shipHeader == null) {
shipEngine = new ShipEngine(orderHeader, user);
}
else {
shipEngine = new ShipEngine(shipHeader, user);
}
shipEngine.setUpdateInventory(form.isUpdateInventory());
initOrder(form, orderHeader, null, null, shipHeader, request);
boolean isValid = validateInput(form, request);
ShipDetailDisplayForm shipDisplays[] = form.getShipDetails();
for (int i = 0; i < shipDisplays.length; i++) {
ShipDetailDisplayForm shipDisplay = shipDisplays[i];
if (!Format.isNullOrEmpty(shipDisplay.getInputShipQtyError())) {
continue;
}
shipEngine.setQty(shipDisplay.getItemSkuCd(), Format.getInt(shipDisplay.getInputShipQty()));
}
shipEngine.calculateHeader();
initOrder(form, orderHeader, null, null, null, request);
if (!isValid) {
Long id = null;
if (!Format.isNullOrEmpty(shipHeaderId)) {
id = Format.getLong(shipHeaderId);
}
calcTotal(form, id, shipEngine);
form.setEditable(true);
form.setNewShip(true);
if (!Format.isNullOrEmpty(shipHeaderId)) {
form.setNewShip(false);
}
em.getTransaction().rollback();
ActionForward actionForward = actionMapping.findForward("error");
return actionForward;
}
saveInput(form, shipEngine);
try {
shipEngine.shipOrder(request);
shipEngine.saveOrder();
OrderEngine orderEngine = new OrderEngine(orderHeader, user);
orderHeader.setOrderStatus(orderEngine.calcStatus(orderHeader));
}
catch (OrderStateException e) {
initOrder(form, orderHeader, null, null, shipHeader, request);
calcTotal(form, shipHeader.getShipHeaderId(), shipEngine);
ActionMessages errors = new ActionMessages();
errors.add("ship", new ActionMessage("error.ship.capture"));
ActionForward actionForward = actionMapping.findForward("error");
saveMessages(request, errors);
form.setEditable(true);
form.setNewShip(false);
return actionForward;
}
catch (AuthorizationException e) {
initOrder(form, orderHeader, null, null, shipHeader, request);
calcTotal(form, shipHeader.getShipHeaderId(), shipEngine);
ActionMessages errors = new ActionMessages();
errors.add("ship", new ActionMessage("error.ship.capture", e.getMessage()));
ActionForward actionForward = actionMapping.findForward("error");
saveMessages(request, errors);
form.setEditable(true);
form.setNewShip(false);
return actionForward;
}
initOrder(form, shipEngine.getOrderHeader(), null, null, shipEngine.getShipHeader(), request);
calcTotal(form, shipEngine.getShipHeader().getShipHeaderId(), shipEngine);
form.setNewShip(false);
form.setAllowCapture(false);
form.setAllowVoid(true);
ActionForward actionForward = actionMapping.findForward("success");