2 namespace Valuation\Report;
6 use Zend\Console\Console;
8 * Stock Contyrol Report.
11 class Valuations extends \Utility\Service\Report
19 protected $_title = 'Valuations Report';
23 protected $_subject = 'Valuations';
27 protected $_description = 'Historical report for valuations.';
31 protected $_notes = array(
32 'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.co.za'
37 protected $_headers = array(
38 'Registration Number',
48 'Loaded on Price Guide',
49 'Date First Offer Received',
50 'Highest Offer Received',
51 'Lowest Offer Received',
52 'Total Offers Received',
58 'Sales Person Surname'
63 protected $_fields = array(
64 'stock_registrationNumber',
80 'valuation_firstName',
81 'valuation_familyName',
83 'valuator_familyName',
90 protected $_totals = array(
100 protected $_currencyFields = array(
113 public function build()
115 #-> Prepare parameters.
118 'stock', 'type', 'damageTotal', 'model', 'make', 'valuation', 'sales', 'valuator', 'priceGuide',
119 'MAX(offer.amount) AS highestOffer',
120 'MIN(offer.amount) AS lowestOffer',
121 'COUNT(offer.id) AS numOffers',
122 'MIN(offer.created) AS firstOfferDate'
128 $query = 'SELECT [SELECTION] '
129 . 'FROM \Valuation\Entity\Valuation valuation '
130 . ' JOIN valuation.stock stock '
131 . ' JOIN stock.type type '
132 . ' JOIN stock.damageTotal damageTotal '
133 . ' JOIN type.model model '
134 . ' JOIN model.make make '
136 . ' LEFT JOIN valuation.valuatedBy valuator '
137 . ' LEFT JOIN valuation.salesProfile sales '
138 . ' LEFT JOIN stock.priceGuide priceGuide '
139 . ' LEFT JOIN priceGuide.offers offer '
142 . 'GROUP BY valuation.id '
143 . 'ORDER BY valuation.created ASC';
145 #-> Construct details.
146 $authData = \Utility\Registry::getAuthData();
147 switch (\Utility\Registry::getUserType())
150 $groupFilter = \Utility\Registry::getSudo('Group', false);
153 $this->_queries['Group'] = \Utility\Registry::getSudo('GroupName');
154 $join[] = 'JOIN stock.company company';
155 $where[] = 'IDENTITY(company.group) = :group';
156 $params['group'] = $groupFilter;
158 $divisionFilter = \Utility\Registry::getSudo('Division', false);
161 $this->_queries['Division'] = \Utility\Registry::getSudo('DivisionName');
162 $join[] = 'JOIN stock.company company';
163 $where[] = 'IDENTITY(company.groupDivision) = :groupDivision';
164 $params['groupDivision'] = $divisionFilter;
166 $companyFilter = \Utility\Registry::getSudo('Company', false);
169 $this->_queries['Company'] = \Utility\Registry::getSudo('CompanyName');
170 $where[] = 'IDENTITY(stock.company) = :company';
171 $params['company'] = $companyFilter;
175 $join[] = 'JOIN stock.company company';
176 $where[] = 'IDENTITY(company.group) = :group';
177 $params['group'] = $authData['company']['group']['id'];
178 $divisionFilter = \Utility\Registry::getSudo('Division', false);
181 $this->_queries['Division'] = \Utility\Registry::getSudo('DivisionName');
182 $join[] = 'JOIN stock.company company';
183 $where[] = 'IDENTITY(company.groupDivision) = :groupDivision';
184 $params['groupDivision'] = $divisionFilter;
186 $companyFilter = \Utility\Registry::getSudo('Company', false);
189 $this->_queries['Company'] = \Utility\Registry::getSudo('CompanyName');
190 $where[] = 'IDENTITY(stock.company) = :company';
191 $params['company'] = $companyFilter;
194 case 'Dealer Principle':
195 $join[] = 'JOIN stock.company company';
196 $where[] = 'IDENTITY(company.groupDivision) = :groupDivision';
197 $params['groupDivision'] = $authData['company']['groupDivision']['id'];
198 $companyFilter = \Utility\Registry::getSudo('Company', false);
201 $this->_queries['Company'] = \Utility\Registry::getSudo('CompanyName');
202 $where[] = 'IDENTITY(stock.company) = :company';
203 $params['company'] = $companyFilter;
207 $where[] = 'IDENTITY(stock.company) = :company';
208 $params['company'] = $authData['company']['id'];
211 if (isset($this->_input['jobState']))
213 $this->_queries['Status'] = $this->_input['jobState'];
214 $where[] = 'valuation.jobState >= :jobState';
215 $params['jobState'] = $this->_input['jobState'];
217 if (isset($this->_input['dateFrom']))
219 $this->_queries['Date Range From'] = $this->_input['dateFrom'];
220 $where[] = 'valuation.created >= :dateFrom';
221 $params['dateFrom'] = new \DateTime($this->_input['dateFrom']);
223 if (isset($this->_input['dateTo']))
225 $this->_queries['Date Range Until'] = $this->_input['dateTo'];
226 $where[] = 'valuation.created <= :dateTo';
227 $params['dateTo'] = new \DateTime($this->_input['dateTo']);
231 $query = str_replace(array(
232 '[SELECTION]', '[JOIN]', '[LEFT-JOIN]', '[WHERE]'
234 implode(', ', $selection) . ' ',
235 implode(' ', $join) . ' ',
236 implode(' ', $leftJion) . ' ',
238 ? 'WHERE ' . implode(' AND ', $where) . ' '
243 $query = $this->em->createQuery($query);
245 && $query->setParameters($params);
246 $this->_data = $query->getScalarResult();
247 $data = $this->_data = $query->getScalarResult();
248 //console.log($this->_data = $query->getScalarResult());
250 var_dump('test',$data);