Conditions | 7 |
Paths | 8 |
Total Lines | 36 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 1 |
1 | <?php |
||
25 | public function calculateAmount(Estimate $estimate) |
||
26 | { |
||
27 | $cats = $this->Categories(); |
||
28 | $all_products = ArrayList::create(); |
||
29 | $value = $estimate->getSubTotal(); |
||
30 | $min = (float) $this->MinOrder; |
||
31 | |||
32 | if ($cats->count() > 0) { |
||
33 | $value = 0; |
||
34 | foreach ($cats as $cat) { |
||
35 | $all_products->merge($cat->Products()); |
||
36 | } |
||
37 | |||
38 | foreach ($estimate->Items() as $line_item) { |
||
39 | $match = $line_item->FindStockItem(); |
||
40 | if ($all_products->find('ID', $match->ID)) { |
||
41 | $value += ($line_item->Quantity * $line_item->UnitPrice); |
||
42 | } |
||
43 | } |
||
44 | } |
||
45 | |||
46 | $converted_value = (int) ($value * 100); |
||
47 | |||
48 | $converted_amount = $converted_value * ($this->Amount / 100); |
||
49 | |||
50 | $amount = MathsHelper::round($converted_amount, 0)/100; |
||
51 | |||
52 | if ($amount > $value) { |
||
53 | $amount = $value; |
||
54 | } |
||
55 | |||
56 | if ($value < $min) { |
||
57 | $amount = 0; |
||
58 | } |
||
59 | |||
60 | return $amount; |
||
61 | } |
||
63 |