| Conditions | 7 |
| Paths | 8 |
| Total Lines | 32 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | public function calculateAmount(Estimate $estimate) |
||
| 20 | { |
||
| 21 | $cats = $this->Categories(); |
||
| 22 | $all_products = ArrayList::create(); |
||
| 23 | $value = $estimate->getSubTotal(); |
||
| 24 | $min = (float) $this->MinOrder; |
||
| 25 | |||
| 26 | if ($cats->count() > 0) { |
||
| 27 | $value = 0; |
||
| 28 | foreach ($cats as $cat) { |
||
| 29 | $all_products->merge($cat->Products()); |
||
| 30 | } |
||
| 31 | |||
| 32 | foreach ($estimate->Items() as $line_item) { |
||
| 33 | $match = $line_item->FindStockItem(); |
||
| 34 | if ($all_products->find('ID', $match->ID)) { |
||
| 35 | $value += ($line_item->Quantity * $line_item->UnitPrice); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | $amount = $this->Amount; |
||
| 41 | |||
| 42 | if ($value < $min) { |
||
| 43 | $amount = 0; |
||
| 44 | } |
||
| 45 | |||
| 46 | if ($amount > $value) { |
||
| 47 | $amount = $value; |
||
| 48 | } |
||
| 49 | |||
| 50 | return $amount; |
||
| 51 | } |
||
| 58 |