Quintiq file version 2.0
|
#parent: #root
|
Method GenerateCombiExistingCampaign (
|
Campaign_MP campaign,
|
output OptCampaignUnitSubPeriod lastocuspforcombicreate,
|
Boolean usemultiperiodcombi
|
) as OptCampaignCombi
|
{
|
Description: 'create combi element that reflects an existing campaign object'
|
TextBody:
|
[*
|
ocusps := selectsortedset( campaign, CampaignPeriod_MP.UnitPeriod.OptCampaignUnitSubPeriod, p, not p.IsFixed() and guard( p.StartTime() > lastocuspforcombicreate.StartTime(), true ), p.StartTime() );
|
combi := null( OptCampaignCombi );
|
|
if ( ocusps.Size() > 0 )
|
{
|
firstocusp := ocusps.Element( 0 );
|
if ( guard( firstocusp.PreviousSubPeriod().IsFixed() and not isnull( firstocusp.PreviousSubPeriod().Transition_MP() ), false ) )
|
{
|
// we need to start out with a single period combi in order to get the sequence constraint right with previous fixed period at start of plan
|
combi := this.GetCombiForExistingPlan( firstocusp );
|
combi.AddCombiElementTransition( firstocusp.PreviousSubPeriod().Transition_MP().TransitionType_MP(), firstocusp );
|
combi.AddCombiElementCampaign( campaign.CampaignType_MP(), firstocusp );
|
ocusps.Remove( firstocusp );
|
lastocuspforcombicreate := firstocusp;
|
}
|
|
if ( usemultiperiodcombi )
|
{
|
firstloop := true;
|
traverse( ocusps, Elements, ocusp )
|
{
|
if ( firstloop ) // for the 1st period, if we have a previous period we must start with that combi element type
|
{
|
combi := this.GetCombiForExistingPlan( ocusp );
|
startingcombielement := ocusp.GetLastElementPreviousSubPeriod();
|
if ( not isnull( startingcombielement ) )
|
{
|
// start of combi with combi element of previous unit sub period
|
type := startingcombielement.GetOptCampaignElementType();
|
combi.AddCombiElement( type, ocusp );
|
}
|
} // endif firstloop
|
|
if ( not firstloop or guard( not combi.LastCombiElement().OptCampaignElementType().Name() = campaign.CampaignTypeName(), true ) ) // add campaign type to combi ( if not already added because of previous period )
|
{
|
combi.AddCombiElementCampaign( campaign.CampaignType_MP(), ocusp );
|
}
|
firstloop := false;
|
lastocuspforcombicreate := ocusp;
|
}
|
}
|
else // not usemultiperiod combi
|
{
|
traverse( ocusps, Elements, ocusp )
|
{
|
combi := this.GetCombiForExistingPlan( ocusp );
|
startingcombielement := ocusp.GetLastElementPreviousSubPeriod();
|
if ( not isnull( startingcombielement ) )
|
{
|
// start of combi with combi element of previous unit sub period
|
type := startingcombielement.GetOptCampaignElementType();
|
combi.AddCombiElement( type, ocusp );
|
}
|
|
if ( guard( not combi.LastCombiElement().OptCampaignElementType().Name() = campaign.CampaignTypeName(), true ) ) // if not added already add campaign type
|
{
|
combi.AddCombiElementCampaign( campaign.CampaignType_MP(), ocusp );
|
}
|
lastocuspforcombicreate := ocusp;
|
}
|
}
|
}
|
return combi;
|
*]
|
InterfaceProperties { Accessibility: 'Module' }
|
}
|