JDBPalletHistory palhistto = new JDBPalletHistory(getHostID(), getSessionID());
JDBControl ctrl = new JDBControl(getHostID(), getSessionID());
String origin = ctrl.getKeyValue("DEFAULT_LOCATION");
JDBMHN mhn = new JDBMHN(getHostID(), getSessionID());
JDBMHNReasons mhnReasons = new JDBMHNReasons(getHostID(), getSessionID());
ResultSet rsFrom = palhistfrom.getInterfacingData(transactionRef, "STATUS CHANGE", "FROM", Long.valueOf(1), "SSCC", "asc");
ResultSet rsTo = palhistfrom.getInterfacingData(transactionRef, "STATUS CHANGE", "TO", Long.valueOf(1), "SSCC", "asc");
try
{
if (rsFrom.next())
{
if (rsTo.next())
{
palhistfrom.getPropertiesfromResultSet(rsFrom);
palhistto.getPropertiesfromResultSet(rsTo);
String mhnNumber = palhistto.getPallet().getMHNNumber();
String initiator = "";
String recorder = "";
String authorisor = "";
String decision = "";
String reason1 = "";
String reason2 = "";
String reason3 = "";
String dateCreated = "";
String dateExpected = "";
String dateResolved = "";
String comment = "";
String status = "";
String locn = "";
if (palhistto.getPallet().getMHNNumber().equals("") == false)
{
if (mhn.getMHNProperties(palhistto.getPallet().getMHNNumber()))
{
initiator = mhn.getInitiator();
recorder = mhn.getRecorder();
authorisor = mhn.getAuthorisor();
reason1 = mhn.getReason1();
reason2 = mhn.getReason2();
reason3 = mhn.getReason3();
dateCreated = JUtility.getISOTimeStampStringFormat(mhn.getDateCreated());
if (dateCreated.equals("Error"))
dateCreated = "";
dateExpected = JUtility.getISOTimeStampStringFormat(mhn.getDateExpected());
if (dateExpected.equals("Error"))
dateExpected = "";
dateResolved = JUtility.getISOTimeStampStringFormat(mhn.getDateResolved());
if (dateResolved.equals("Error"))
dateResolved = "";
comment = mhn.getComments();
status = mhn.getStatus();
}
}
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.newDocument();
Element message = (Element) document.createElement("message");
Element hostUniqueID = addElement(document, "hostRef", Common.hostList.getHost(getHostID()).getUniqueID());
message.appendChild(hostUniqueID);
Element messageRef = addElement(document, "messageRef", String.valueOf(transactionRef));
message.appendChild(messageRef);
Element messageType = addElement(document, "interfaceType", "Pallet Status Change");
message.appendChild(messageType);
Element messageInformation = addElement(document, "messageInformation", "SSCC=" + palhistto.getPallet().getSSCC());
message.appendChild(messageInformation);
Element messageDirection = addElement(document, "interfaceDirection", "Output");
message.appendChild(messageDirection);
Element messageDate = addElement(document, "messageDate", JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime()));
message.appendChild(messageDate);
Element palletStatusChange = (Element) document.createElement("palletStatusChange");
Element sscc = addElement(document, "SSCC", palhistto.getPallet().getSSCC());
palletStatusChange.appendChild(sscc);
Element material = addElement(document, "material", palhistto.getPallet().getMaterial());
palletStatusChange.appendChild(material);
Element batch = addElement(document, "batch", palhistto.getPallet().getBatchNumber());
palletStatusChange.appendChild(batch);
Element source = addElement(document,"origin",origin);
palletStatusChange.appendChild(source);
locn = palhistfrom.getPallet().getLocationID();
Element location = addElement(document, "location", palhistto.getPallet().getLocationID());
palletStatusChange.appendChild(location);
Element quantity = addElement(document, "quantity", palhistto.getPallet().getQuantity().toString());
palletStatusChange.appendChild(quantity);
Element uom = addElement(document, "uom", palhistto.getPallet().getUom().toString());
palletStatusChange.appendChild(uom);
Element despNo = addElement(document, "despatchNumber", palhistto.getPallet().getDespatchNo());
palletStatusChange.appendChild(despNo);
Element statusFrom = addElement(document, "statusFrom", palhistfrom.getPallet().getStatus());
palletStatusChange.appendChild(statusFrom);
Element statusTo = addElement(document, "statusTo", palhistto.getPallet().getStatus());
palletStatusChange.appendChild(statusTo);
decision = palhistto.getPallet().getDecision();
Element masterHoldNoticeData = (Element) document.createElement("masterHoldNoticeData");
Element mhnNo = addElement(document, "MHN", mhnNumber);
masterHoldNoticeData.appendChild(mhnNo);
Element mhnRecorder = addElement(document, "recorder", recorder);
masterHoldNoticeData.appendChild(mhnRecorder);
Element mhnInitiator = addElement(document, "initiator", initiator);
masterHoldNoticeData.appendChild(mhnInitiator);
Element mhnAuthorisor = addElement(document, "authorisor", authorisor);
masterHoldNoticeData.appendChild(mhnAuthorisor);
Element mhnDecision = addElement(document, "decision", decision);
masterHoldNoticeData.appendChild(mhnDecision);
Element masterHoldReasons = (Element) document.createElement("reasons");
if (reason1.equals("") == false)
{
Element masterHoldReason = (Element) document.createElement("reason");
Element mhnReason1 = addElement(document, "code", reason1);
masterHoldReason.appendChild(mhnReason1);
mhnReasons.getReasonProperties(reason1);
String reason1desc = mhnReasons.getDescription();
Element mhnReason1desc = addElement(document, "description", reason1desc);
masterHoldReason.appendChild(mhnReason1desc);
masterHoldReasons.appendChild(masterHoldReason);
}
if (reason2.equals("") == false)
{
Element masterHoldReason = (Element) document.createElement("reason");
Element mhnReason2 = addElement(document, "code", reason2);
masterHoldReason.appendChild(mhnReason2);
mhnReasons.getReasonProperties(reason2);
String reason2desc = mhnReasons.getDescription();
Element mhnReason2desc = addElement(document, "description", reason2desc);
masterHoldReason.appendChild(mhnReason2desc);
masterHoldReasons.appendChild(masterHoldReason);
}
if (reason3.equals("") == false)
{
Element masterHoldReason = (Element) document.createElement("reason");
Element mhnReason3 = addElement(document, "code", reason3);
masterHoldReason.appendChild(mhnReason3);
mhnReasons.getReasonProperties(reason3);
String reason3desc = mhnReasons.getDescription();
Element mhnReason3desc = addElement(document, "description", reason3desc);
masterHoldReason.appendChild(mhnReason3desc);
masterHoldReasons.appendChild(masterHoldReason);
}