GenericValue returnItem = null;
try {
returnItem = delegator.findByPrimaryKey("ReturnItem", UtilMisc.toMap("returnId", returnId, "returnItemSeqId", returnItemSeqId));
} catch (GenericEntityException e) {
Debug.logError(e, module);
throw new GeneralRuntimeException(e.getMessage());
}
Debug.log("Return item value object - " + returnItem, module);
// check for an orderItem association
if (returnItem != null) {
String orderId = returnItem.getString("orderId");
String orderItemSeqId = returnItem.getString("orderItemSeqId");
if (orderItemSeqId != null && orderId != null) {
Debug.log("Found order item reference", module);
// locate the item issuance(s) for this order item
List itemIssue = null;
try {
itemIssue = delegator.findByAnd("ItemIssuance", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId));
} catch (GenericEntityException e) {
Debug.logError(e, module);
throw new GeneralRuntimeException(e.getMessage());
}
if (UtilValidate.isNotEmpty(itemIssue)) {
Debug.log("Found item issuance reference", module);
// just use the first one for now; maybe later we can find a better way to determine which was the
// actual item being returned; maybe by serial number
GenericValue issue = EntityUtil.getFirst(itemIssue);
GenericValue inventoryItem = null;
try {
inventoryItem = issue.getRelatedOne("InventoryItem");
} catch (GenericEntityException e) {
Debug.logError(e, module);
throw new GeneralRuntimeException(e.getMessage());
}
if (inventoryItem != null) {
Debug.log("Located inventory item - " + inventoryItem.getString("inventoryItemId"), module);
if (inventoryItem.get("unitCost") != null) {
itemCost = inventoryItem.getBigDecimal("unitCost");