1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\OrdersAdmin\Extensions; |
4
|
|
|
|
5
|
|
|
use SilverStripe\ORM\DataExtension; |
6
|
|
|
use SilverStripe\Forms\FieldList; |
7
|
|
|
use SilverStripe\Forms\DropdownField; |
8
|
|
|
use SilverStripe\Forms\GridField\GridFieldDetailForm; |
9
|
|
|
use SilverStripe\Core\Config\Config; |
10
|
|
|
use SilverStripe\Security\Member; |
11
|
|
|
use SilverCommerce\OrdersAdmin\Forms\GridField\OrdersDetailForm; |
12
|
|
|
use SilverCommerce\OrdersAdmin\Model\Invoice; |
13
|
|
|
use SilverCommerce\OrdersAdmin\Model\Estimate; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Add additional functions to a contact |
17
|
|
|
*/ |
18
|
|
|
class ContactExtension extends DataExtension |
19
|
|
|
{ |
|
|
|
|
20
|
|
|
private static $has_many = [ |
|
|
|
|
21
|
|
|
"Invoices" => Invoice::class, |
22
|
|
|
"Estimates"=> Estimate::class |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
public function updateCMSFields(FieldList $fields) |
26
|
|
|
{ |
27
|
|
|
// Filter the invoice list |
28
|
|
|
$invoices_field = $fields->dataFieldByName("Invoices"); |
29
|
|
|
$estimate_field = $fields->dataFieldByName("Estimates"); |
30
|
|
|
|
31
|
|
|
if ($invoices_field) { |
|
|
|
|
32
|
|
|
$invoices_field |
33
|
|
|
->getConfig() |
34
|
|
|
->removeComponentsByType(GridFieldDetailForm::class) |
35
|
|
|
->addComponent(new OrdersDetailForm()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if ($estimate_field) { |
|
|
|
|
39
|
|
|
$list = $estimate_field->getList(); |
40
|
|
|
$list = $list->filter("ClassName", Estimate::class); |
41
|
|
|
$estimate_field->setList($list); |
42
|
|
|
$estimate_field |
43
|
|
|
->getConfig() |
44
|
|
|
->removeComponentsByType(GridFieldDetailForm::class) |
45
|
|
|
->addComponent(new OrdersDetailForm()); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get all orders that have been generated and are marked |
51
|
|
|
* as paid or processing |
52
|
|
|
* |
53
|
|
|
* @return DataList |
|
|
|
|
54
|
|
|
*/ |
55
|
|
|
public function OutstandingInvoices() |
56
|
|
|
{ |
57
|
|
|
return $this |
58
|
|
|
->owner |
59
|
|
|
->Invoices() |
60
|
|
|
->filter("Status", Config::inst()->get(Invoice::class, "outstanding_statuses")); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get all orders that have been generated and are marked |
65
|
|
|
* as dispatched or canceled |
66
|
|
|
* |
67
|
|
|
* @return DataList |
68
|
|
|
*/ |
69
|
|
|
public function HistoricInvoices() |
70
|
|
|
{ |
71
|
|
|
return $this |
72
|
|
|
->owner |
73
|
|
|
->Invoices() |
74
|
|
|
->filter("Status", Config::inst()->get(Invoice::class, "historic_statuses")); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function canView($member) |
78
|
|
|
{ |
79
|
|
|
// Members can view their own records |
80
|
|
|
if ($member && $member->exists() && $member->ID == $this->owner->MemberID) { |
81
|
|
|
return true; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function canEdit($member) |
86
|
|
|
{ |
87
|
|
|
// Members can edit their own records |
88
|
|
|
if ($member && $member->exists() && $member->ID == $this->owner->MemberID) { |
89
|
|
|
return true; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function canDelete($member) |
94
|
|
|
{ |
95
|
|
|
// Members can delete their own records |
96
|
|
|
if ($member && $member->exists() && $member->ID == $this->owner->MemberID) { |
97
|
|
|
return true; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|