Quintiq file version 2.0
#parent: #root
Method CreateShadowConversionFactor () id:Method_FormUnitsOfMeasurement_CreateShadowConversionFactor
{
  #keys: '[124808.2.631315687]'
  Body:
  [*
    // Generate conversion factor shadow instances
    DataHolderShadowGlobalParameters.Data( null( shadow[GlobalParameters_MP], owning ) );
    
    //Ownership on GP so that it is possible to show multi rows when multiple uoms are selected.
    owner := shadow( MacroPlan.GlobalParameters_MP() );
    DataHolderShadowGlobalParameters.Data( &owner );
    
    traverse( DataHolderMatrixEditorRows.Data(), Elements, rowheader )
    {
      traverse( DataHolderMatrixEditorColumns.Data(), Elements, colheader, rowheader <> colheader )
      {           
        baseconversionfactor := null( BaseConversionFactor );
        
        // Get conversion factor regardless it is base or inverse, to show Factor value in matrix
        conversionfactor := select( rowheader, AsSourceUnitOfMeasure, cf,
                                    not cf.IsProductDependent(),
                                    cf.TargetUnitOfMeasure() = colheader );
        
        // Need to set relation to base conversion factor
        // If it is base, relset straight away.
        if( not isnull( conversionfactor ) )
        {                                   
          if( conversionfactor.istype( BaseConversionFactor ) )
          {     
            baseconversionfactor := conversionfactor.astype( BaseConversionFactor );
          }
          // Else if it is inverse, relset the base conversion factor the inverse factor belongs to.
          else
          {
            baseconversionfactor := conversionfactor.astype( InverseConversionFactor ).BaseConversionFactor();
          }
        }
    
        // Create shadow conversion factor in matrix
        DataHolderShadowGlobalParameters.Data().ConversionFactorInMatrix( relnew,
                                                                          SourceUnitOfMeasureInConversionMatrix := rowheader,
                                                                          TargetUnitOfMeasureInConversionMatrix := colheader,
                                                                          BaseConversionFactor  := baseconversionfactor,
                                                                          Factor := guard( conversionfactor.Factor(), 1 ) );
                                                                                     
       }
    }
  *]
}
