Under which circumstances work order can be cancelled ?

Explanation
1) System will allow cancellation of only those workorders where no material has been allocated or any material issued through workorder issue.
2) If any workorder issue has been generated, then all such material must be shown as returned to stores
3) if any material has been allocated against this workorder, then it must be deallocated before that workorder can be closed.
4) Workorder cancellation will be allowed for all the workorders in Plan, Firm Plan, Release and Undo Firm Plan stage
5) If any issue, confirmed or unconfirmed, exists for a workorder to be cancelled, then the system will not allow cancellation for that workorder
6) If any confirmed workorder issue exists and no other material has been allocated, then the system will allow cancellation after all materials shown in that issue are returned to stores
7) If any unconfirmed workorder issue exists, then the system will allow cancellation after all the material has been de-allocated for that operation.
8) A cancelled workorder can neither be edited nor be allowed to firm plan or release