Payable::TotalPaid()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.2
cc 4
eloc 7
nc 2
nop 0
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