Quintiq file version 2.0
|
#parent: #root
|
Method MPSyncActualUnitPeriod (
|
Boolean isoverwritemanualconfig,
|
IOActualUnitPeriods ioactualunitperiods
|
)
|
{
|
Description: 'Synchronization of ActualUnitPeriod for MPSync'
|
TextBody:
|
[*
|
// Select a set of existing ActualUnitPeriod
|
existing := selectset( this, Actual.astype( ActualUnitPeriod ), item, true );
|
updates := construct( ActualUnitPeriods );
|
|
// Traverse the new set of valid ActualUnitPeriod
|
traverse( ioactualunitperiods , Elements, io, io.IsValid() )
|
{
|
// Find existing ActualUnitPeriod
|
objectinstance := ActualUnitPeriod::FindActualUnitPeriodTypeIndex( io.UnitID(), io.Date() );
|
|
// If no existing ActualUnitPeriod is found, create one
|
if( isnull( objectinstance ) )
|
{
|
objectinstance := ActualUnitPeriod::Create( this,
|
io.ActualTotalAvailableDuration(),
|
io.ActualTotalAvailableQuantity(),
|
io.ActualUtilizationPercentage(),
|
'', // it is declaratively created
|
io.Date(),
|
io.Description(),
|
io.UnitID(),
|
true );
|
}
|
// Else if the ActualUnitPeriod is not manually configured or the imported Actual should overwrite manual configuration,
|
// update the existing ActualUnitPeriod
|
else if( not objectinstance.IsManuallyConfigured() or isoverwritemanualconfig )
|
{
|
// Update ActualUnitPeriod
|
objectinstance.Update( io.ActualUtilizationPercentage(),
|
io.ActualTotalAvailableQuantity(),
|
io.ActualTotalAvailableDuration(),
|
io.Description(),
|
true );
|
updates.Add( objectinstance );
|
}
|
|
if( not isnull( objectinstance ) )
|
{
|
objectinstance.CustomUpdate( io, isoverwritemanualconfig );
|
}
|
}
|
|
// Get the set of old ActualUnitPeriod to be deleted
|
tobedeleteset := existing.Difference( updates );
|
|
// Traverse the set of ActualUnitPeriod to be deleted
|
// Only delete ActualUnitPeriod that is not manually configured or the imported Actual should overwrite manual configuration
|
traverse( tobedeleteset, Elements, ele,
|
not ele.IsManuallyConfigured() or isoverwritemanualconfig )
|
{
|
ele.Delete();
|
}
|
*]
|
}
|