2 namespace Report\Report;
9 class AdminValuation extends \Utility\Service\Report
14 protected $_title = 'Valuation Report';
18 protected $_subject = 'Valuations';
22 protected $_description = 'Historical report for valuations.';
26 protected $_notes = array(
27 'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.com.na'
32 protected $_headers = array(
38 'Customer Phone Number',
39 'Registration Number',
49 'Price Offered to Sales',
65 protected $_fields = array(
67 'companyDivision_name',
69 'valuation_firstName',
70 'valuation_familyName',
72 'stock_registrationNumber',
82 'valuation_amountOffered',
86 'valuation_sentToSales',
89 'valuation_salesComments',
91 'dealNotDoneSelection_name',
92 'valuation_dealNotDoneReason',
93 'sendToStockFrom_name'
98 protected $_totals = array(
102 'stock_highestOffer',
103 'valuation_amountOffered'
108 protected $_currencyFields = array(
112 'stock_highestOffer',
113 'valuation_amountOffered'
121 public function build()
123 #-> Prepare parameters.
125 'valuation', 'stock', 'createdBy', 'company', 'type', 'model', 'make',
126 'vehicleYear', 'salesProfile', 'managerProfile', 'companyGroup', 'companyDivision',
127 'sendToStockFrom', 'dealNotDoneSelection'
131 $query = 'SELECT [SELECTION] '
132 . 'FROM \Valuation\Entity\Valuation valuation '
133 . 'JOIN valuation.stock stock '
134 . 'JOIN valuation.createdBy createdBy '
135 . 'JOIN stock.company company '
136 . 'JOIN stock.vehicleYear vehicleYear '
137 . 'JOIN stock.type type '
138 . 'JOIN type.model model '
139 . 'JOIN model.make make '
140 . 'LEFT JOIN valuation.salesProfile salesProfile '
141 . 'LEFT JOIN valuation.managerProfile managerProfile '
142 . 'LEFT JOIN company.group companyGroup '
143 . 'LEFT JOIN company.groupDivision companyDivision '
144 . 'LEFT JOIN valuation.sendToStockFrom sendToStockFrom '
145 . 'LEFT JOIN valuation.dealNotDoneSelection dealNotDoneSelection '
147 . 'ORDER BY valuation.created ASC';
149 #-> Construct details.
150 if (isset($this->_input['dateFrom']) && !empty($this->_input['dateFrom']))
152 $this->_queries['Date Range From'] = $this->_input['dateFrom'];
153 $where[] = 'valuation.created >= :dateFrom';
154 $params['dateFrom'] = new \DateTime($this->_input['dateFrom']);
156 if (isset($this->_input['dateTo']) && !empty($this->_input['dateTo']))
158 $this->_queries['Date Range Until'] = $this->_input['dateTo'];
159 $where[] = 'valuation.created <= :dateTo';
160 $params['dateTo'] = new \DateTime($this->_input['dateTo'] . ' 23:59:59');
162 if (isset($this->_input['group'])
163 && !empty($this->_input['group'])
164 && 'null' != $this->_input['group'])
166 $this->_queries['Group'] = $this->em
167 ->find('\Company\Entity\Group', $this->_input['group'])
169 $where[] = 'companyGroup.id = :group';
170 $params['group'] = $this->_input['group'];
172 if (isset($this->_input['groupDivision'])
173 && !empty($this->_input['groupDivision'])
174 && 'null' != $this->_input['groupDivision'])
176 $this->_queries['Division'] = $this->em
177 ->find('\Company\Entity\GroupDivision', $this->_input['groupDivision'])
179 $where[] = 'companyDivision.id = :division';
180 $params['division'] = $this->_input['groupDivision'];
182 if (isset($this->_input['company'])
183 && !empty($this->_input['company'])
184 && 'null' != $this->_input['company'])
186 $this->_queries['Dealership'] = $this->em
187 ->find('\Company\Entity\Company', $this->_input['company'])
189 $where[] = 'company.id = :company';
190 $params['company'] = $this->_input['company'];
194 $query = str_replace(array(
195 '[SELECTION]', '[WHERE]'
197 implode(', ', $selection) . ' ',
199 ? 'WHERE ' . implode(' AND ', $where) . ' '
204 $query = $this->em->createQuery($query);
206 && $query->setParameters($params);
208 $this->_data = $query->getScalarResult();
211 foreach ($this->_data as $rowId => $rowData)
213 // \Utility\Debug::errorLog('$rowId', $rowId);
214 // \Utility\Debug::errorLog('$rowData', $rowData);
216 $this->_data[$rowId]['createdBy_fullName'] = $rowData['createdBy_firstName'] . ' ' . $rowData['createdBy_familyName'];
217 $this->_data[$rowId]['sales_person'] = isset($rowData['salesProfile_firstName'])
218 && !empty($rowData['salesProfile_firstName'])
219 ? $rowData['salesProfile_firstName'] . ' ' . $rowData['salesProfile_familyName']
221 $this->_data[$rowId]['manager'] = isset($rowData['managerProfile_firstName'])
222 && !empty($rowData['managerProfile_firstName'])
223 ? $rowData['managerProfile_firstName'] . ' ' . $rowData['managerProfile_familyName']
225 if ($this->_data[$rowId]['stock_tradePrice'] == 0)
227 $this->_data[$rowId]['percentage_trade'] = '0 %';
231 $this->_data[$rowId]['percentage_trade'] = round(($this->_data[$rowId]['valuation_amountOffered'] * 100) / $this->_data[$rowId]['stock_tradePrice']) . ' %' ;