Code Duplication    Length = 59-60 lines in 2 locations

code/reports/CurrentOrdersReport.php 1 location

@@ 16-75 (lines=60) @@
13
 *
14
 **/
15
16
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

code/reports/UnprintedOrderReport.php 1 location

@@ 16-74 (lines=59) @@
13
 *
14
 **/
15
16
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