SalesAdmin::getEditForm()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
dl 0
loc 22
rs 9.2568
c 0
b 0
f 0
nc 4
nop 2
1
<?php
2
3
4
/**
5
 * @description: CMS management for everything you have sold and all related data (e.g. logs, payments)
6
 *
7
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
8
 * @package: ecommerce
9
 * @sub-package: cms
10
 * @inspiration: Silverstripe Ltd, Jeremy
11
 **/
12
class SalesAdmin extends ModelAdminEcommerceBaseClass
13
{
14
    /**
15
     * standard SS variable.
16
     *
17
     * @var string
18
     */
19
    private static $url_segment = 'sales';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
20
21
    /**
22
     * standard SS variable.
23
     *
24
     * @var string
25
     */
26
    private static $menu_title = 'Sales to Action';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
27
28
    /**
29
     * standard SS variable.
30
     *
31
     * @var int
32
     */
33
    private static $menu_priority = 3.1;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
34
35
    /**
36
     * Change this variable if you don't want the Import from CSV form to appear.
37
     * This variable can be a boolean or an array.
38
     * If array, you can list className you want the form to appear on. i.e. array('myClassOne','myClasstwo').
39
     */
40
    public $showImportForm = false;
41
42
    /**
43
     * standard SS variable.
44
     *
45
     * @var string
46
     */
47
    private static $menu_icon = 'ecommerce/images/icons/money-file.gif';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
48
49
    public function init()
50
    {
51
        parent::init();
52
        Requirements::javascript('ecommerce/javascript/EcomBuyableSelectField.js');
53
        //Requirements::themedCSS("OrderReport", 'ecommerce'); // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
54
        //Requirements::themedCSS("Order_Invoice", 'ecommerce', "print"); // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
55
        //Requirements::themedCSS("Order_PackingSlip", 'ecommerce', "print"); // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
56
        //Requirements::themedCSS("OrderStepField",'ecommerce'); // LEAVE HERE
57
        //Requirements::javascript("ecommerce/javascript/EcomModelAdminExtensions.js"); // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
58
    }
59
60
    public function urlSegmenter()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
61
    {
62
        return $this->config()->get('url_segment');
63
    }
64
65
    /**
66
     * @return array Map of class name to an array of 'title' (see {@link $managed_models})
67
     *               we make sure that the Order Admin is FIRST
68
     */
69
    public function getManagedModels()
70
    {
71
        $models = parent::getManagedModels();
72
        $orderModelManagement = isset($models['Order']) ? $models['Order'] : null;
73
        if ($orderModelManagement) {
74
            unset($models['Order']);
75
76
            return array('Order' => $orderModelManagement) + $models;
77
        }
78
79
        return $models;
80
    }
81
82
83
    /**
84
     * @return DataList
85
     */
86
    public function getList()
87
    {
88
        $list = parent::getList();
89
        if (is_subclass_of($this->modelClass, 'Order') || $this->modelClass === 'Order') {
90
            $queueObjectSingleton = Injector::inst()->get('OrderProcessQueue');
91
            $ordersinQueue = $queueObjectSingleton->OrdersInQueueThatAreNotReady();
92
            $list = $list
93
                ->filter(
94
                    array(
95
                        "CancelledByID" => 0,
96
                        "StatusID:greaterThan" => 0
97
                    )
98
                )
99
                ->exclude(
100
                    array(
101
                        'ID' => $ordersinQueue->column('ID'),
102
                    )
103
                );
104
            //you can only do one exclude at the same time.
105
            $list = $list
106
                ->exclude(
107
                    array(
108
                        'StatusID' => OrderStep::non_admin_manageable_steps()->column('ID')
109
                    )
110
                );
111
        }
112
113
        $newLists = $this->extend('updateGetList', $list);
114
        if (is_array($newLists) && count($newLists)) {
115
            foreach ($newLists as $newList) {
116
                if ($newList instanceof DataList) {
117
                    $list = $newList;
118
                }
119
            }
120
        }
121
        return $list;
122
    }
123
124
125
    public function getEditForm($id = null, $fields = null)
126
    {
127
        $form = parent::getEditForm($id, $fields);
128
        if (is_subclass_of($this->modelClass, 'Order') || $this->modelClass === 'Order') {
129
            if ($gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass))) {
130
                if ($gridField instanceof GridField) {
131
                    $config = $gridField->getConfig();
132
                    $exportButton = new GridFieldExportSalesButton('buttons-before-left');
133
                    $exportButton->setExportColumns($this->getExportFields());
134
                    $config->addComponent($exportButton);
135
                    $printAllInvoices = new GridFieldPrintAllInvoicesButton('buttons-before-left');
136
                    $config->addComponent($printAllInvoices);
137
                    $printAllPackingSlips = new GridFieldPrintAllPackingSlipsButton('buttons-before-left');
138
                    $config->addComponent($printAllPackingSlips);
139
                    //per row ...
140
                    $config->addComponent(new GridFieldPrintInvoiceButton());
141
                    // $config->addComponent(new GridFieldPrintPackingSlipButton());
142
                }
143
            }
144
        }
145
        return $form;
146
    }
147
}
148