Payable   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A TotalPaid() 0 11 4
A updateCMSFields() 0 11 1
1
<?php
2
3
/**
4
 * An extension for providing payments on a particular data object.
5
 *
6
 * @package payment
7
 */
8
class Payable extends DataExtension {
9
10
	private static $has_many = array(
11
		'Payments' => 'Payment'
12
	);
13
14
	public function updateCMSFields(FieldList $fields) {
15
		$fields->addFieldToTab("Root.Payments",
16
			GridField::create("Payments", "Payments", $this->owner->Payments(),
17
				GridFieldConfig_RecordEditor::create()
18
					->removeComponentsByType('GridFieldAddNewButton')
19
					->removeComponentsByType('GridFieldDeleteAction')
20
					->removeComponentsByType('GridFieldFilterHeader')
21
					->removeComponentsByType('GridFieldPageCount')
22
			)
23
		);
24
	}
25
26
	public function TotalPaid() {
27
		$paid = 0;
28
		if ($payments = $this->owner->Payments()) {
29
			foreach ($payments as $payment) {
30
				if ($payment->Status == 'Captured') {
31
					$paid += $payment->Amount;
32
				}
33
			}
34
		}
35
		return $paid;
36
	}
37
38
}
39