Created
December 23, 2009 15:46
-
-
Save MarkMenard/262590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calculateStatus (Lot lot) { | |
// TODO Should we look at using a State pattern here? -Mark 11/10/09 | |
// TODO LoD refactoring | |
def tos = lot.incomingOrderLineItem.shipmentLineItems.container.transportOrderLineItems.transportOrder.findAll { it.status != 'CANCELLED' } | |
def result = null | |
// Status | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : Calculating status " | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : Original status = ${lot.status}" | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : lot.quantityOnHand = ${lot.quantityOnHand}" | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : lot.onHandInventoryItems = ${lot.onHandInventoryItems}" | |
// TODO LoD refactoring | |
def shipments = lot.incomingOrderLineItem.shipmentLineItems.shipment.findAll { it.status != 'CANCELLED' } | |
// Check to make sure the lot is still complete | |
if (lot.status == 'COMPLETE' && (lot.quantityOnHand > 0 || lot.onHandInventoryItems > 0)) { | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : lot.quantityOnHand = ${lot.quantityOnHand}" | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : lot.onHandInventoryItems = ${lot.onHandInventoryItems}" | |
result = 'RECEIVED' | |
lot.dateOfCompletion = null | |
} | |
// If not has been Received and quantityOnHand is 0 and Items on hand is 0 then the lot is COMPLETE. | |
// Also set the dateOfCompletion == Last Outgoing shipment. | |
if ( (lot.status == 'RECEIVED' || lot.status == 'COMPLETE' ) && lot.quantityOnHand == 0 && lot.onHandInventoryItems == 0) { | |
result = 'COMPLETE' | |
log.debug "[LotDependencyManagerImpl.groovy]: lot.number : ${lot.number}" | |
// TODO LoD refactoring | |
lot.dateOfCompletion = lot.fulfillmentLineItems.findAll{it.fulfillment.fulfillmentType.id == 'ALLOCATION'}.shipmentLineItem.shipment.findAll { | |
it.shipmentType.id =~ /OUTBOUND/ || it.shipmentType.id == 'TRANSFER' | |
}.collect { | |
it.dateOfDeparture | |
}.max() | |
// If the order has been CANCELLED or the line item forced closed then the lot is also CANCELLED. | |
} else if (lot.incomingOrderLineItem.order.status == 'CANCELLED' || lot.incomingOrderLineItem.status == 'FORCED_CLOSED' ) { | |
result = 'CANCELLED' | |
} else if (lot.status == 'DROPPED' || lot.status == 'IN_WORK') { | |
if (lot.quantityReceivedNet > 0) { | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : lot.quantityOnHand = ${lot.quantityOnHand}" | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : lot.onHandInventoryItems = ${lot.onHandInventoryItems}" | |
lot.dateOfCompletion = null // Reset the Date to null | |
result = 'RECEIVED' | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : Lot was either 'DROPPED' or 'IN_WORK and is now 'RECEIVED'. " | |
} else { | |
// Do nothing. We assume a human being has set this status. | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : Lot is 'DROPPED' or 'IN_WORK' but has no receipts. Leaving unchanged." | |
} | |
} else { | |
if (lot.quantityReceivedNet > 0 ) { | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : lot.quantityOnHand = ${lot.quantityOnHand}" | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : lot.onHandInventoryItems = ${lot.onHandInventoryItems}" | |
if ( lot.status != 'COMPLETE' ) { | |
lot.dateOfCompletion = null // Reset the Date to null | |
result = 'RECEIVED' | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : lot.quantityReceived > 0 setting status to 'RECEIVED' " | |
} | |
} else if (shipments.size() == 0) { // There are no shipments the lot is either NO_INFO or PROJECTED depending on the status of incomingOrderLineItem.shipmentConfirmed. | |
if (lot.incomingOrderLineItem.partialDocumentsReceived) { | |
result = 'PARTIAL_INFO' | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : There are no shipments or receipts associated with the lot." | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : The order line item has been marked partial documents received, setting status to 'PARTIAL_INFO'" | |
} else if (lot.incomingOrderLineItem.vendorConfirmed) { | |
result = 'VENDOR_CONFIRMED' | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : There are no shipments or receipts associated with the lot." | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : The order line item has been vendor confirmed, setting status to 'VENDOR_CONFIRMED'" | |
} else { | |
result = 'NO_INFO' | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : There are no shipments or receipts associated with the lot setting status to 'NO_INFO'." | |
} | |
} else { // Time to analyze the status of shipments and to's. | |
def shipmentType = shipments[0].shipmentType.id | |
switch (shipmentType) { | |
case 'IMPORT_INBOUND' : | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : Processing an import lot." | |
// If the lot has an INLAND TO then it is scheduled. | |
def inlandTos = tos.findAll { it.transportOrderType.id == 'INLAND' && it.status != "CANCELLED" } | |
if (inlandTos.size() > 0) { | |
result = 'SCHEDULED' | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : The lot has an INLAND TO and no receipts setting status to 'SCHEDULED'." | |
} else { | |
result = 'PROJECTED' | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : The lot has no INLAND TO or receipts setting status to 'PROJECTED'." | |
} | |
break | |
case 'DOMESTIC_INBOUND' : | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : Processing a domestic lot." | |
if (tos.size() > 0) { | |
// A TO has been scheduled for the delivery. So the lot is scheduled. | |
result = 'SCHEDULED' | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : The lot has a TO and no receipts settting status to 'SCHEDULED'." | |
} else { | |
result = 'NO_INFO' | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : The lot has no TO or receipts setting status to 'PROJECTED'." | |
} | |
break | |
case 'TRANSFER' : | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : Processing a transfer lot." | |
if (tos.size() > 0) { | |
log.debug "[LotDependencyManagerImpl.groovy]: tos.size() : ${tos.size()}" | |
// A TO has been scheduled for the delivery. So the lot is scheduled. | |
result = 'SCHEDULED' | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : The lot has a TO and no receipts settting status to 'SCHEDULED'." | |
} else { | |
if ( lot.incomingOrderLineItem.shipmentLineItems.size() > 0 ) { | |
result = "PROJECTED" | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : The lot has no TO or receipts setting status to 'PROJECTED'." | |
} else { | |
result = 'NO_INFO' | |
} | |
} | |
break | |
default : throw new RuntimeException ("ERROR: Unhandled shipment type: ${shipmentType}") | |
} | |
} | |
} | |
log.debug "[ LotDependencyManagerImpl ]: [${lot.id}] : Calculated status = ${result}" | |
log.debug "" | |
if (result == null) { | |
throw new RuntimeException ("ERROR: No status was calculated for lot ${lot.number}.") | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment