1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* An extension to {@link SSReport} that allows a user |
4
|
|
|
* to view all Order instances in the system that |
5
|
|
|
* are not printed. {@link UnprintedOrderReport->getReportField()} |
6
|
|
|
* outlines the logic for what orders are considered to be "unprinted". |
7
|
|
|
* |
8
|
|
|
* |
9
|
|
|
* @authors: Silverstripe, Jeremy, Nicolaas |
10
|
|
|
* |
11
|
|
|
* @package: ecommerce |
12
|
|
|
* @sub-package: reports |
13
|
|
|
* |
14
|
|
|
**/ |
15
|
|
|
|
16
|
|
View Code Duplication |
class UnprintedOrderReport extends SS_Report |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
protected $title = 'Unprinted Orders'; |
19
|
|
|
|
20
|
|
|
protected $description = 'This shows all orders that are complete, but haven\'t been printed yet.'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Return a {@link ComplexTableField} that shows |
24
|
|
|
* all Order instances that are not printed. That is, |
25
|
|
|
* Order instances with the property "Printed" value |
26
|
|
|
* set to "0". |
27
|
|
|
* |
28
|
|
|
* @return ComplexTableField |
29
|
|
|
*/ |
30
|
|
|
public function getReportField() |
31
|
|
|
{ |
32
|
|
|
// Get the fields used for the table columns |
33
|
|
|
$fields = Order::get_summary_fields(); |
34
|
|
|
|
35
|
|
|
// Add some fields specific to this report |
36
|
|
|
$fields['Invoice'] = ''; |
37
|
|
|
$fields['Print'] = ''; |
38
|
|
|
|
39
|
|
|
$table = new TableListField( |
40
|
|
|
'Orders', |
41
|
|
|
'Order', |
42
|
|
|
$fields |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
// Customise the SQL query for Order, because we don't want it querying |
46
|
|
|
// all the fields. Invoice and Printed are dummy fields that just have some |
47
|
|
|
// text in them, which would be automatically queried if we didn't specify |
48
|
|
|
// a custom query. |
49
|
|
|
$query = singleton('Order')->buildSQL('"Order"."Printed" = 0', '"Order"."Created" DESC'); |
50
|
|
|
$query->groupby[] = '"Order"."Created"'; |
51
|
|
|
$table->setCustomQuery($query); |
52
|
|
|
|
53
|
|
|
// Set the links to the Invoice and Print fields allowing a user to view |
54
|
|
|
// another template for viewing an Order instance |
55
|
|
|
$table->setFieldFormatting(array( |
56
|
|
|
'Invoice' => '<a href=\"OrderReport_Popup/invoice/$ID\">Invoice</a>', |
57
|
|
|
'Print' => '<a target=\"_blank\" href=\"OrderReport_Popup/index/$ID?print=1\">Print</a>' |
58
|
|
|
)); |
59
|
|
|
|
60
|
|
|
$table->setFieldCasting(array( |
61
|
|
|
'Created' => 'Date', |
62
|
|
|
'Total' => 'Currency->Nice' |
63
|
|
|
)); |
64
|
|
|
|
65
|
|
|
$table->setPermissions(array( |
66
|
|
|
'edit', |
67
|
|
|
'show', |
68
|
|
|
'export', |
69
|
|
|
'delete', |
70
|
|
|
)); |
71
|
|
|
|
72
|
|
|
return $table; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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.