Characteristics that have so far determined the material are the number, price and position price. The position price is formed by a simple formula.
However, it is often the case that the position price of a material is formed from different proportions, e.g. number, profit margin or discount.
We are now expanding our material with the features of
Number
Percentage profit margin
Position price
The percentage profit margin for materials is 38%
Thus, the position price is calculated at
Number * Price * (1 + Profit Margin / 100)
We modify the class material:
The feature number has already been created in the Tabular output of the material section.
After that, we create the feature [Profit margin]. This one is of the type Double. It is initialized with 38.
Next, the feature [Position price] will be modified. We delete the Get event and we check, if the feature is using currency factors.
Then, we create a function named Calculation for example, to determine the position price.
The function must not have any parameters and is triggered by a so-called Event rule.
In the function, the calculation of the position price is performed.
[Position Price] := NumberOf * Price * (1 + [Profit margin] / 100)
Of course, checking the calculation is not very high performant for each rule check, especially for a large number of objects. However, appropriate actions can be taken to improve this.
- Possibility: Examination for change of influencing features
- Possibility: Boolean helper variable and AfterLet events
A Boolean helper variable can be created, which is set in the AfterLet events of the influencing features and is resetted in the calculation function.
Create a Boolean variable Changed.
Create an AfterLet event for all influencing features:
Private Function AfterLet() As Void
Changed := True
End Function
Change the Calculation function in the following way:
Public Function Calculation() As Void
Changed := False
[Position Price] := NumberOf * Price * (1 + [Profit margin] / 100)
End Function
The event rule now looks like this:
Since the total value of the material is now the [Position price] feature, the Get Event of the Total feature in the Start class must be adjusted:
Private Function Get(ByRef Value As Currency) As Void
Dim M As ::Material, t As Currency := 0
For Each M In Me.ObjectList(::Material,, True)
t += M.[Position Price]
End For
Value := t
End Function
(knowledge base Tutorial Stage 9)