83) COC Table method
/// <summary>
/// The <c>AVAEntAssetWorkOrderTableDbt_Extension</c> contains the TransMountain extending logic for the <c>EntAssetWorkOrderTable</c> table.
/// </summary>
[ExtensionOf(tableStr(EntAssetWorkOrderTable))]
final class AvaEntAssetWorkOrderTable_Extension
{
// <summary>
// To fill the Year of issue field with the current year on system
// </summary>
public void initValue()
{
next initValue();
this.avaInitFromWorkOrderType();
}
// <summary>
// To modifiedfield call the "avaInitFromWorkOrderType" method to check the works order type
// </summary>
public void modifiedField(FieldId _fieldId)
{
next modifiedField(_fieldId);
switch (_fieldId)
{
case fieldNum(EntAssetWorkOrderTable, WorkOrderType):
this.avaInitFromWorkOrderType();
break;
}
}
// <summary>
// Method will check that work order type what is the work order classification selected on work order typr form
// </summary>
public void avaInitFromWorkOrderType()
{
if(this.workordertype().AVAWorkOrderTypeClassification == AVAWorkOrderTypeClassification::Pipeline)
{
this.AvaPipelineYearofIssue = year(DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()));
}
else
{
this.AvaPipelineYearofIssue = 0;
}
}
public AvaIvaraJobID AvaAvaraJobId()
{
EntAssetWorkOrderLine workOrderLine;
EntAssetRoundTable roundTable;
select firstonly AvaIvaraJobID from roundTable
where roundTable.AvaIvaraJobID != ""
exists join workOrderLine
where workOrderLine.RefTableId == tableNum(EntAssetRoundTable)
&& workOrderLine.RefRecId == roundTable.RecId
&& workOrderLine.WorkOrder == this.RecId;
return roundTable.AvaIvaraJobID;
}
public boolean AvaHasShippedTransfer()
{
InventTransferLine transferLineLocal;
InventTransferTable transferTableLocal;
if (!this)
return false;
select firstonly RecId from transferTableLocal
where transferTableLocal.AvaWorkOrderTable == this.RecId
exists join transferLineLocal where transferLineLocal.QtyRemainReceive != 0
&& transferTableLocal.TransferId == transferLineLocal.TransferId
&& transferLineLocal.AvaWorkOrderLine != 0;
return transferTableLocal.RecId != 0;
}
public boolean AvaHasTransfer()
{
InventTransferLine transferLineLocal;
InventTransferTable transferTableLocal;
if (!this)
return false;
select firstonly RecId from transferTableLocal
where transferTableLocal.AvaWorkOrderTable == this.RecId;
return transferTableLocal.RecId != 0;
}
// <summary>
// Method will initialize values from maintenance program
// </summary>
public void avaInitFromMaintenanceProgram(AvaEntAssetMaintenanceProgram _maintenanceProgram)
{
this.AvaMaintenanceProgram = _maintenanceProgram.RecId;
this.AvaPipelineKMPost = _maintenanceProgram.PipelineKMPost;
this.AvaPipelineGirthWeld = _maintenanceProgram.PipelineGirthWeld;
this.AvaPipelineYearofIssue = _maintenanceProgram.PipelineYearofIssue;
this.AvaLatitude = _maintenanceProgram.Latitude;
this.AvaLongitude = _maintenanceProgram.Longitude;
this.AvaCMRNum = _maintenanceProgram.CMRNum;
this.AvaHazardId = _maintenanceProgram.HazardId;
this.AvaPipelineDigNum = _maintenanceProgram.MaintenanceProgramId;
this.WorkOrderType = _maintenanceProgram.WorkOrderType;
this.ResponsibleWorkerGroup = _maintenanceProgram.MaintenanceGroup;
this.ResponsibleWorker = _maintenanceProgram.ProgramManager;
if (!this.ExpectedStart)
{
this.ExpectedStart = _maintenanceProgram.ExpectedStartDate;
}
}
// <summary>
// add pool reference for maintenance program WO
// </summary>
public void avaCreateMaintenanceProgramWorkOrderPoolReference()
{
EntAssetWorkOrderPoolRelation poolRelation;
AvaEntAssetMaintenanceProgram maintenanceProgram;
maintenanceProgram = AvaEntAssetMaintenanceProgram::findRecId(this.AvaMaintenanceProgram);
if (maintenanceProgram.WorkOrderPool && this.RecId)
{
ttsBegin;
if (!EntAssetWorkOrderPoolRelation::exist(maintenanceProgram.WorkOrderPool, this.RecId))
{
poolRelation.clear();
poolRelation.WorkOrderPool = AvaEntAssetMaintenanceProgram::findRecId(this.AvaMaintenanceProgram).WorkOrderPool;
poolRelation.WorkOrder = this.RecId;
if (poolRelation.validateWrite())
{
poolRelation.insert();
}
else
{
throw error(strfmt("@SYS4007721", tablePname(EntAssetWorkOrderPoolRelation)));
}
}
ttsCommit;
}
}
public void insert(boolean _updateState)
{
next insert(_updateState);
if (this.AvaMaintenanceProgram)
{
this.avaCreateMaintenanceProgramWorkOrderPoolReference();
EntAssetWorkOrderTable::avaUpdateMaintenanceStatus(this.AvaMaintenanceProgram);
}
}
/// <summary>
/// Will update the work order status on the basis of transfer order
/// FDD : - EXT_004_TrackItemShipment
/// </summary>
public void update()
{
next update();
if (this.AvaMaintenanceProgram)
{
EntAssetWorkOrderTable::avaUpdateMaintenanceStatus(this.AvaMaintenanceProgram);
}
}
/// <summary>
/// Will update the work order status on the basis of transfer order
/// FDD : - EXT_004_TrackItemShipment
/// </summary>
public void delete()
{
next delete();
if (this.AvaMaintenanceProgram)
{
EntAssetWorkOrderTable::avaUpdateMaintenanceStatus(this.AvaMaintenanceProgram);
}
}
/// <summary>
/// update the maintenance program on the basis of work order lif state
/// </summary>
public static void avaUpdateMaintenanceStatus(AvaMaintenanceProgramRecId _maintenanceProgramRecId)
{
EntAssetWorkOrderTable workOrderTable;
AvaMaintenanceProgramStatus minProgramStatus;
EntAssetWorkOrderLifecycleState workOrderLifecycleState;
EntAssetWorkOrderLifecycleState workOrderLifecycleStateInProgress;
EntAssetWorkOrderLifecycleState workOrderLifecycleStateMax;
select minof(AvaMaintenanceProgramStatus) from workOrderLifecycleState
join workOrderTable
where workOrderTable.AvaMaintenanceProgram == _maintenanceProgramRecId
&& workOrderTable.WorkOrderLifecycleState == workOrderLifecycleState.RecId;
if (workOrderLifecycleState)
{
select AvaMaintenanceProgramStatus from workOrderLifecycleStateInProgress
where workOrderLifecycleStateInProgress.AvaMaintenanceProgramStatus == AvaMaintenanceProgramStatus::InProgress
join workOrderTable
where workOrderTable.AvaMaintenanceProgram == _maintenanceProgramRecId
&& workOrderTable.WorkOrderLifecycleState == workOrderLifecycleStateInProgress.RecId;
if (workOrderLifecycleStateInProgress.AvaMaintenanceProgramStatus)
{
minProgramStatus = workOrderLifecycleStateInProgress.AvaMaintenanceProgramStatus;
}
else
{
select maxof(AvaMaintenanceProgramStatus) from workOrderLifecycleStateMax
join workOrderTable
where workOrderTable.AvaMaintenanceProgram == _maintenanceProgramRecId
&& workOrderTable.WorkOrderLifecycleState == workOrderLifecycleStateMax.RecId;
if (workOrderLifecycleStateMax.AvaMaintenanceProgramStatus != workOrderLifecycleState.AvaMaintenanceProgramStatus)
{
if (workOrderLifecycleState.AvaMaintenanceProgramStatus == AvaMaintenanceProgramStatus::Finished)
{
minProgramStatus = AvaMaintenanceProgramStatus::Finished;
}
else
{
minProgramStatus = AvaMaintenanceProgramStatus::InProgress;
}
}
else
{
minProgramStatus = workOrderLifecycleState.AvaMaintenanceProgramStatus;
}
}
}
else
{
minProgramStatus = AvaMaintenanceProgramStatus::New;
}
ttsbegin;
AvaEntAssetMaintenanceProgram maintenanceProgram = AvaEntAssetMaintenanceProgram::findRecId(_maintenanceProgramRecId, true);
if (maintenanceProgram)
{
maintenanceProgram.Status = minProgramStatus;
maintenanceProgram.doUpdate();
}
ttscommit;
}
}
Comments
Post a Comment