2 namespace Report\Report;
10 class Valuation extends \Utility\Service\Report
18 protected $_title = 'Valuation Report';
22 protected $_subject = 'Valuations';
26 protected $_description = 'Historical report for valuations.';
30 protected $_notes = array(
31 'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.com.na'
36 protected $_headers = array(
40 'Customer Phone Number',
41 'Customer Email Address',
42 'Registration Number',
48 'Customer Requested Price',
51 'Price Offered to Sales',
67 protected $_fields = array(
69 'valuation_firstName',
70 'valuation_familyName',
73 'stock_registrationNumber',
79 'valuation_requiredPrice',
82 'valuation_amountOffered',
86 'valuation_sentToSales',
89 'valuation_salesComments',
91 'dealNotDoneSelection_name',
92 'valuation_dealNotDoneReason',
93 'sendToStockFrom_name'
98 protected $_totals = array(
99 'valuation_requiredPrice',
102 'stock_highestOffer',
103 'valuation_amountOffered'
108 protected $_currencyFields = array(
109 'valuation_requiredPrice',
112 'stock_highestOffer',
113 'valuation_amountOffered'
121 public function build()
123 #-> Prepare parameters.
124 ini_set('memory_limit','512M');
125 $authData = \Utility\Registry::getAuthData();
127 'valuation', 'stock', 'createdBy', 'company', 'type', 'model', 'make',
128 'vehicleYear', 'salesProfile', 'managerProfile', 'companyGroup', 'companyDivision',
129 'sendToStockFrom', 'dealNotDoneSelection'
135 $query = 'SELECT [SELECTION] '
136 . 'FROM \Valuation\Entity\Valuation valuation '
137 . 'JOIN valuation.stock stock '
138 . 'JOIN valuation.createdBy createdBy '
139 . 'JOIN stock.company company '
140 . 'JOIN stock.vehicleYear vehicleYear '
141 . 'JOIN stock.type type '
142 . 'JOIN type.model model '
143 . 'JOIN model.make make '
144 . 'LEFT JOIN valuation.salesProfile salesProfile '
145 . 'LEFT JOIN valuation.managerProfile managerProfile '
146 . 'LEFT JOIN company.group companyGroup '
147 . 'LEFT JOIN company.groupDivision companyDivision '
148 . 'LEFT JOIN valuation.sendToStockFrom sendToStockFrom '
149 . 'LEFT JOIN valuation.dealNotDoneSelection dealNotDoneSelection '
151 . 'ORDER BY valuation.created ASC';
153 #-> Construct details.
154 $authData = \Utility\Registry::getAuthData();
155 if (isset($this->_input['dateFrom']) && !empty($this->_input['dateFrom']))
157 $this->_queries['Date Range From'] = $this->_input['dateFrom'];
158 $where[] = 'valuation.created >= :dateFrom';
159 $params['dateFrom'] = new \DateTime($this->_input['dateFrom']);
161 if (isset($this->_input['dateTo']) && !empty($this->_input['dateTo']))
163 $this->_queries['Date Range Until'] = $this->_input['dateTo'];
164 $where[] = 'valuation.created <= :dateTo';
165 $params['dateTo'] = new \DateTime($this->_input['dateTo'] . ' 23:59:59');
167 #-> Construct details.
168 $authData = \Utility\Registry::getAuthData();
169 switch (\Utility\Registry::getUserType())
173 $groupFilter = \Utility\Registry::getSudo('Group', false);
174 if ($groupFilter && 0 != $groupFilter)
176 $this->_queries['Group'] = \Utility\Registry::getSudo('GroupName', false);
177 $join[] = 'JOIN stock.company company';
178 $where[] = 'IDENTITY(company.group) = :group';
179 $params['group'] = $groupFilter;
181 $divisionFilter = \Utility\Registry::getSudo('Division', false);
182 if ($divisionFilter && 0 != $divisionFilter)
184 $this->_queries['Division'] = \Utility\Registry::getSudo('DivisionName', false);
185 $join[] = 'JOIN stock.company company';
186 $where[] = 'IDENTITY(company.groupDivision) = :groupDivision';
187 $params['groupDivision'] = $divisionFilter;
189 $companyFilter = \Utility\Registry::getSudo('Company', false);
190 if ($companyFilter && 0 != $companyFilter)
192 $this->_queries['Company'] = \Utility\Registry::getSudo('CompanyName', false);
193 $where[] = 'IDENTITY(stock.company) = :company';
194 $params['company'] = $companyFilter;
198 $join[] = 'JOIN stock.company company';
199 $where[] = 'IDENTITY(company.group) = :group';
200 $params['group'] = $authData['company']['group']['id'];
201 $divisionFilter = \Utility\Registry::getSudo('Division', false);
202 if ($divisionFilter && 0 != $divisionFilter)
204 $this->_queries['Division'] = \Utility\Registry::getSudo('DivisionName', false);
205 $join[] = 'JOIN stock.company company';
206 $where[] = 'IDENTITY(company.groupDivision) = :groupDivision';
207 $params['groupDivision'] = $divisionFilter;
209 $companyFilter = \Utility\Registry::getSudo('Company', false);
210 if ($companyFilter && 0 != $companyFilter)
212 $this->_queries['Company'] = \Utility\Registry::getSudo('CompanyName', false);
213 $where[] = 'IDENTITY(stock.company) = :company';
214 $params['company'] = $companyFilter;
217 case 'Dealer Principle':
218 $join[] = 'JOIN stock.company company';
219 $where[] = 'IDENTITY(company.groupDivision) = :groupDivision';
220 $params['groupDivision'] = $authData['company']['groupDivision']['id'];
221 $companyFilter = \Utility\Registry::getSudo('Company', false);
222 if ($companyFilter && 0 != $companyFilter)
224 $this->_queries['Company'] = \Utility\Registry::getSudo('CompanyName', false);
225 $where[] = 'IDENTITY(stock.company) = :company';
226 $params['company'] = $companyFilter;
230 $where[] = 'IDENTITY(stock.company) = :company';
231 $params['company'] = $authData['company']['id'];
236 $query = str_replace(array(
237 '[SELECTION]', '[WHERE]'
239 implode(', ', $selection) . ' ',
241 ? 'WHERE ' . implode(' AND ', $where) . ' '
246 $query = $this->em->createQuery($query);
248 && $query->setParameters($params);
250 $this->_data = $query->getScalarResult();
253 foreach ($this->_data as $rowId => $rowData)
255 $this->_data[$rowId]['createdBy_fullName'] = $rowData['createdBy_firstName'] . ' ' . $rowData['createdBy_familyName'];
256 $this->_data[$rowId]['sales_person'] = isset($rowData['salesProfile_firstName'])
257 && !empty($rowData['salesProfile_firstName'])
258 ? $rowData['salesProfile_firstName'] . ' ' . $rowData['salesProfile_familyName']
260 $this->_data[$rowId]['manager'] = isset($rowData['managerProfile_firstName'])
261 && !empty($rowData['managerProfile_firstName'])
262 ? $rowData['managerProfile_firstName'] . ' ' . $rowData['managerProfile_familyName']
264 if ($this->_data[$rowId]['stock_tradePrice'] == 0)
266 $this->_data[$rowId]['percentage_trade'] = '0 %';
270 $this->_data[$rowId]['percentage_trade'] = round(($this->_data[$rowId]['valuation_amountOffered'] * 100) / $this->_data[$rowId]['stock_tradePrice']) . ' %' ;