CreditHeader creditHeader = null;
if (!Format.isNullOrEmpty(creditHeaderId)) {
creditHeader = (CreditHeader) em.find(CreditHeader.class, Format.getLong(form.getCreditHeaderId()));
}
CreditEngine creditEngine = null;
if (creditHeader == null) {
creditEngine = new CreditEngine(invoiceHeader, user);
}
else {
creditEngine = new CreditEngine(creditHeader, user);
}
creditEngine.setShippingTotal(0);
ActionMessages messages = validateOther(form);
if (messages.size() == 0) {
creditEngine.setShippingTotal(Format.getFloat(form.getInputShippingTotal()));
}
initOrder(form, orderHeader, null, creditHeader, null, request);
boolean isValid = validateInput(form, request);
if (!isValid) {
initOrder(form, orderHeader, null, null, null, request);
Long id = null;
if (!Format.isNullOrEmpty(creditHeaderId)) {
id = Format.getLong(creditHeaderId);
}
calcTotal(form, id, creditEngine);
form.setEditable(true);
form.setNewCredit(true);
if (!Format.isNullOrEmpty(creditHeaderId)) {
form.setNewCredit(false);
}
em.getTransaction().rollback();
ActionForward actionForward = actionMapping.findForward("error");
return actionForward;
}
saveInput(form, creditEngine);
try {
creditEngine.creditOrder(request);
creditEngine.saveOrder();
invoiceHeader.setInvoiceStatus(creditEngine.calcStatus(invoiceHeader));
orderHeader.setOrderStatus(creditEngine.calcStatus(orderHeader));
}
catch (OrderStateException e) {
initOrder(form, orderHeader, null, creditHeader, null, request);
calcTotal(form, creditHeader.getCreditHeaderId(), creditEngine);
ActionMessages errors = new ActionMessages();
errors.add("credit", new ActionMessage("error.credit.capture"));
ActionForward actionForward = actionMapping.findForward("error");
saveMessages(request, errors);
form.setAllowCapture(true);
form.setEditable(true);
form.setNewCredit(false);
return actionForward;
}
catch (AuthorizationException e) {
initOrder(form, orderHeader, null, creditHeader, null, request);
calcTotal(form, creditHeader.getCreditHeaderId(), creditEngine);
ActionMessages errors = new ActionMessages();
errors.add("credit", new ActionMessage("error.credit.capture", e.getMessage()));
ActionForward actionForward = actionMapping.findForward("error");
saveMessages(request, errors);
form.setAllowCapture(true);
form.setEditable(true);
form.setNewCredit(false);
return actionForward;
}
initOrder(form, creditEngine.getOrderHeader(), null, creditEngine.getCreditHeader(), null, request);
calcTotal(form, creditEngine.getCreditHeader().getCreditHeaderId(), creditEngine);
form.setNewCredit(false);
form.setAllowCapture(false);
form.setAllowVoid(true);
ActionForward actionForward = actionMapping.findForward("success");