1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class SecondHandProductValue extends SS_Report |
|
|
|
|
5
|
|
|
{ |
6
|
|
|
/** |
7
|
|
|
* The class of object being managed by this report. |
8
|
|
|
* Set by overriding in your subclass. |
9
|
|
|
*/ |
10
|
|
|
protected $dataClass = 'SecondHandProduct'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @return string |
14
|
|
|
*/ |
15
|
|
|
public function title() |
16
|
|
|
{ |
17
|
|
|
$values = $this->sourceRecords()->column('PurchasePrice'); |
18
|
|
|
$sum = array_sum($values); |
19
|
|
|
$object = Currency::create('Sum'); |
20
|
|
|
$object->setValue($sum); |
21
|
|
|
$name = _t( |
22
|
|
|
'EcommerceSideReport.SECOND_HAND_REPORT_TOTAL_STOCK_VALUE', |
23
|
|
|
'Second Hand Products, total stock value' |
24
|
|
|
); |
25
|
|
|
return $name . ': ' . $object->Nice(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* not sure if this is used in SS3. |
30
|
|
|
* |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
|
|
public function group() |
34
|
|
|
{ |
35
|
|
|
return _t('EcommerceSideReport.ECOMMERCEGROUP', 'Ecommerce'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return int - for sorting reports |
40
|
|
|
*/ |
41
|
|
|
public function sort() |
42
|
|
|
{ |
43
|
|
|
return 8000; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* working out the items. |
48
|
|
|
* |
49
|
|
|
* @return DataList |
50
|
|
|
*/ |
51
|
|
|
public function sourceRecords($params = null) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
return SecondHandProduct::get()->filter( |
54
|
|
|
array( |
55
|
|
|
'AllowPurchase' => 1, |
56
|
|
|
'SellingOnBehalf' => 0 |
57
|
|
|
) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return array |
63
|
|
|
*/ |
64
|
|
|
public function columns() |
65
|
|
|
{ |
66
|
|
|
return array( |
67
|
|
|
'InternalItemID' => 'ID', |
68
|
|
|
'Title' => array( |
69
|
|
|
'title' => 'Product Name', |
70
|
|
|
'link' => true, |
71
|
|
|
), |
72
|
|
|
'Created' => 'Created Time', |
73
|
|
|
'Price' => 'Selling Price', |
74
|
|
|
'PurchasePrice' => 'Purchase Price' |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getReportField() |
79
|
|
|
{ |
80
|
|
|
$field = parent::getReportField(); |
81
|
|
|
$config = $field->getConfig(); |
82
|
|
|
$exportButton = $config->getComponentByType('GridFieldExportButton'); |
83
|
|
|
$exportButton->setExportColumns($field->getColumns()); |
84
|
|
|
|
85
|
|
|
return $field; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.