1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* An extension to {@link SSReport} that allows a user |
4
|
|
|
* to view all Order instances that are "current", |
5
|
|
|
* {@link CurrentOrdersReport->getReportField()} has |
6
|
|
|
* the detail on the logic for what "Current" means. |
7
|
|
|
* |
8
|
|
|
* |
9
|
|
|
* @authors: Silverstripe, Jeremy, Nicolaas |
10
|
|
|
* |
11
|
|
|
* @package: ecommerce |
12
|
|
|
* @sub-package: reports |
13
|
|
|
* |
14
|
|
|
**/ |
15
|
|
|
|
16
|
|
View Code Duplication |
class CurrentOrdersReport extends SS_Report |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
protected $title = 'Current Orders'; |
19
|
|
|
|
20
|
|
|
protected $description = 'This shows all orders that are not paid or cancelled.'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Return a {@link ComplexTableField} that shows |
24
|
|
|
* all Order instances that are current. |
25
|
|
|
* |
26
|
|
|
* "Current" means all Orders that don't have a |
27
|
|
|
* Status property of "Complete" or "Cancelled". |
28
|
|
|
* |
29
|
|
|
* @return ComplexTableField |
30
|
|
|
*/ |
31
|
|
|
public function getReportField() |
32
|
|
|
{ |
33
|
|
|
// Get the fields used for the table columns |
34
|
|
|
$fields = Order::get_summary_fields(); |
35
|
|
|
|
36
|
|
|
// Add some fields specific to this report |
37
|
|
|
$fields['Invoice'] = ''; |
38
|
|
|
$fields['Print'] = ''; |
39
|
|
|
|
40
|
|
|
$table = new TableListField( |
41
|
|
|
'Orders', |
42
|
|
|
'Order', |
43
|
|
|
$fields |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
// Customise the SQL query for Order, because we don't want it querying |
47
|
|
|
// all the fields. Invoice and Printed are dummy fields that just have some |
48
|
|
|
// text in them, which would be automatically queried if we didn't specify |
49
|
|
|
// a custom query. |
50
|
|
|
$query = singleton('Order')->buildSQL("\"Order\".\"Status\" NOT IN ('Complete', 'Cancelled')", '"Order"."Created" DESC'); |
51
|
|
|
$query->groupby[] = '"Order"."Created"'; |
52
|
|
|
$table->setCustomQuery($query); |
53
|
|
|
|
54
|
|
|
// Set the links to the Invoice and Print fields allowing a user to view |
55
|
|
|
// another template for viewing an Order instance |
56
|
|
|
$table->setFieldFormatting(array( |
57
|
|
|
'Invoice' => '<a href=\"OrderReport_Popup/invoice/$ID\">Invoice</a>', |
58
|
|
|
'Print' => '<a target=\"_blank\" href=\"OrderReport_Popup/index/$ID?print=1\">Print</a>' |
59
|
|
|
)); |
60
|
|
|
|
61
|
|
|
$table->setFieldCasting(array( |
62
|
|
|
'Created' => 'Date', |
63
|
|
|
'Total' => 'Currency->Nice' |
64
|
|
|
)); |
65
|
|
|
|
66
|
|
|
$table->setPermissions(array( |
67
|
|
|
'edit', |
68
|
|
|
'show', |
69
|
|
|
'export', |
70
|
|
|
'delete', |
71
|
|
|
)); |
72
|
|
|
|
73
|
|
|
return $table; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.