latest update
[namibia] / module / Report / src / Report / Report / NoMatch.php
1 <?php
2 namespace Report\Report;
3
4
5
6 /**
7  * Stock Control Report.
8  * @author andre.fourie
9  */
10 class NoMatch extends \Utility\Service\Report
11 {
12
13
14
15         /**
16          * @var string
17          */
18         protected $_title  = 'NoMatch Report';
19         /**
20          * @var string
21          */
22         protected $_subject = 'NoMatch';
23         /**
24          * @var string
25          */
26         protected $_description = 'Details of vehicles NOT found on Bid4Cars auction that was sold/invoiced through automate.';
27         /**
28          * @var array
29          */
30         protected $_notes = array(
31                         'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.com.na'
32         );
33         /**
34          * @var array
35          */
36         protected $_headers = array(
37                         'Invoice Number',
38                         'Stock Number',
39                         'Make',
40                         'VIN',
41                         'Registration',
42                         'Engine',
43                         'Sale Date',
44                         'Standing Value',
45                         'Invoiced',
46                         'Sold To'
47         );
48         /**
49          * @var array
50          */
51         protected $_fields = array(
52                         'invoicenumber',
53                         'stocknumber',
54                         'make',
55                         'vin',
56                         'registration',
57                         'engine',
58                         'saledate',
59                         'standingvalue',
60                         'invoiced',
61                         'soldto'
62         );
63         
64         /**
65          * Build the dataset.
66          */
67         public function build()
68         {
69                 ini_set('memory_limit','512M');
70
71                 #-> Prepare parameters.
72                 $selection = array(
73                                 'adherence', 'stock'
74                 );
75                 $join      = array();
76                 $leftJion  = array();
77                 $where     = array('stock.id is null');
78                 $params    = array();
79                 $query = 'SELECT [SELECTION] '
80                                 . 'FROM \Adherence\Entity\Adherence adherence '
81                                 . 'LEFT JOIN adherence.stock stock '
82                                 . '[WHERE]  ';
83                                 //. 'ORDER BY adherence.id ASC, auction.id ASC';
84                 
85                 #-> Construct details.
86         $authData = \Utility\Registry::getAuthData();
87                 if (isset($this->_input['dateFrom']) && !empty($this->_input['dateFrom']))
88                 {
89                         $this->_queries['Date Range From'] = $this->_input['dateFrom'];
90                         $where[] = 'adherence.dateSold >= :dateFrom';
91                         $params['dateFrom'] = new \DateTime($this->_input['dateFrom']);
92                 }
93                 if (isset($this->_input['dateTo']) && !empty($this->_input['dateTo']))
94                 {
95                         $this->_queries['Date Range Until'] = $this->_input['dateTo'];
96                         $where[] = 'adherence.dateSold <= :dateTo';
97                         $params['dateTo'] = new \DateTime($this->_input['dateTo'] . ' 23:59:59');
98                 }
99                 
100                 #-> Finalize query.
101                 $query = str_replace(array(
102                                 '[SELECTION]', '[WHERE]'
103                         ), array(
104                                 implode(', ', $selection) . ' ',
105                                 !empty($where)
106                                         ? 'WHERE ' . implode(' AND ', $where) . ' '
107                                         : ' '
108                         ), $query);
109
110                 #-> Collect data.
111                 $query = $this->em->createQuery($query);
112                 !empty($params)
113                         && $query->setParameters($params);
114                 $data = $query->getScalarResult();
115                 $this->em->clear();
116                 
117                 //\Utility\Debug::errorLog('data', $data);
118                 //var_dump($data);
119                 //exit();
120                 
121                 foreach ($data as $id => $row)
122                 {
123                         $this->_data[] = array(
124                                         
125                                         'invoicenumber'                 => '',
126                                         'stocknumber'                   => $row['adherence_stockNumber'],
127                                         'make'                                  => $row['adherence_make'],
128                                         'vin'                                   => $row['adherence_vinNumber'],
129                                         'registration'                  => $row['adherence_registrationNumber'],
130                                         'engine'                                => $row['adherence_engineNumber'],
131                                         'saledate'                              => $row['adherence_dateSold'],
132                                         'standingvalue'                 => $row['adherence_amount'],
133                                         'invoiced'                              => '',
134                                         'soldto'                                => $row['adherence_soldTo']
135                         );
136                 }
137         }
138
139 }