2 namespace Report\Report;
8 * Stock Control Report.
11 class PriceGuideFlash extends \Utility\Service\Report
19 protected $_title = 'PriceGuide Flash Report';
23 protected $_subject = 'PriceGuide Flash';
27 protected $_description = 'Amount of valuations send to price guide.';
31 protected $_notes = array(
32 'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.com.na'
37 protected $_headers = array(
39 'Total Cars Loaded on Price Guide',
42 'Total number of offers made',
44 'Number with 3 offers +',
46 'Number with 2 offers',
48 'Number with 1 offer',
50 'Number with 0 offers',
56 protected $_fields = array(
79 public function build()
81 ini_set('memory_limit','512M');
87 $stockWhere = array();
90 if (!isset($this->_input['dateFrom']) || empty($this->_input['dateFrom']))
92 $this->_input['dateFrom'] = date('Y-m-d', mktime(1, 1, 1, date('m' - 1), 1, date('Y')));
94 $this->_queries['Date Range From'] = $this->_input['dateFrom'];
95 $where[] = 'priceGuide.created >= :dateFrom';
96 $stockWhere[] = 'stock.created >= :dateFrom';
97 $params['dateFrom'] = new \DateTime($this->_input['dateFrom']);
99 if (!isset($this->_input['dateTo']) || empty($this->_input['dateTo']))
101 $this->_input['dateTo'] = date('Y-m-d', mktime(23, 59, 59, date('m'), 0, date('Y')));
103 $this->_queries['Date Range Until'] = $this->_input['dateTo'];
104 $where[] = 'priceGuide.created < :dateTo';
105 $stockWhere[] = 'stock.created < :dateTo';
106 $params['dateTo'] = new \DateTime($this->_input['dateTo'] . ' 00:00:01');
108 if (isset($this->_input['group'])
109 && !empty($this->_input['group'])
110 && 'null' != $this->_input['group'])
112 $this->_queries['Group'] = $this->em
113 ->find('\Company\Entity\Group', $this->_input['group'])
115 $where[] = 'IDENTITY(company.group) = :group';
116 $stockWhere[] = 'IDENTITY(company.group) = :group';
117 $params['group'] = $this->_input['group'];
119 if (isset($this->_input['groupDivision'])
120 && !empty($this->_input['groupDivision'])
121 && 'null' != $this->_input['groupDivision'])
123 error_log($this->_input['groupDivision']);
124 $this->_queries['Division'] = $this->em
125 ->find('\Company\Entity\GroupDivision', $this->_input['groupDivision'])
127 $where[] = 'IDENTITY(company.groupDivision) = :division';
128 $stockWhere[] = 'IDENTITY(company.groupDivision) = :division';
129 $params['division'] = $this->_input['groupDivision'];
131 if (isset($this->_input['company'])
132 && !empty($this->_input['company'])
133 && 'null' != $this->_input['company'])
135 $this->_queries['Dealership'] = $this->em
136 ->find('\Company\Entity\Company', $this->_input['company'])
138 $where[] = 'company.id = :company';
139 $stockWhere[] = 'company.id = :company';
140 $params['company'] = $this->_input['company'];
143 #-> Total Cars Loaded
144 $query = 'SELECT COUNT(stock.id) as CarsLoaded '
145 . 'FROM \Stock\Entity\Stock stock '
146 . 'JOIN stock.company company '
148 $query = str_replace(array(
152 ? 'WHERE ' . implode(' AND ', $stockWhere) . ' '
155 $query = $this->em->createQuery($query);
157 && $query->setParameters($params);
158 $data0 = $query->getScalarResult();
161 #-> Total Cars Loaded on price guide
162 $query = 'SELECT COUNT(DISTINCT priceGuide.id) AS CarsLoaded '
163 . 'FROM \PriceGuide\Entity\PriceGuide priceGuide '
164 . 'JOIN priceGuide.company company '
166 $query = str_replace(array(
170 ? 'WHERE ' . implode(' AND ', $where) . ' '
173 $query = $this->em->createQuery($query);
175 && $query->setParameters($params);
176 $data1 = $query->getScalarResult();
179 //\Utility\Debug::errorLog('data', $params);
183 #-> Total cars that has offers
184 $query = 'SELECT COUNT(DISTINCT priceGuide.id) AS NumCarsWithOffers '
185 . 'FROM \PriceGuide\Entity\PriceGuide priceGuide '
186 . 'JOIN priceGuide.company company '
187 . 'JOIN priceGuide.offers offer '
189 $query = str_replace(array(
193 ? 'WHERE ' . implode(' AND ', $where) . ' '
196 $query = $this->em->createQuery($query);
198 && $query->setParameters($params);
199 $data2 = $query->getScalarResult();
202 #-> Total cars that has offers vs cars loaded in %
203 $data3 = 0 == $data1[0]['CarsLoaded']
205 : round(($data2[0]['NumCarsWithOffers']*100)/$data1[0]['CarsLoaded']);
207 #-> Total number of offers made
209 $query = 'SELECT COUNT(DISTINCT offers.id) AS NumOffersMade '
210 . 'FROM \PriceGuide\Entity\PriceGuide priceGuide '
211 . 'JOIN priceGuide.company company '
212 . 'JOIN priceGuide.offers offers '
214 $query = str_replace(array(
218 ? 'WHERE ' . implode(' AND ', $where) . ' '
221 $query = $this->em->createQuery($query);
223 && $query->setParameters($params);
224 $data4 = $query->getScalarResult();
227 #-> Ave number of offers per Cars Loaded
228 $data5 = 0 == $data1[0]['CarsLoaded']
230 : round($data4[0]['NumOffersMade']/$data1[0]['CarsLoaded']);
232 #-> Number with 3+ offers
233 $query = 'SELECT priceGuide.id, COUNT(offer.id) AS numOffers '
234 . 'FROM \PriceGuide\Entity\PriceGuide priceGuide '
235 . 'JOIN priceGuide.company company '
236 . 'LEFT JOIN priceGuide.offers offer '
238 . 'GROUP BY priceGuide.id '
239 . 'HAVING numOffers > 2';
240 $query = str_replace(array(
244 ? 'WHERE ' . implode(' AND ', $where) . ' '
247 $query = $this->em->createQuery($query);
249 && $query->setParameters($params);
250 $data6 = count($query->getScalarResult());
253 #-> Number with 3 offers %
254 $data7 = 0 == $data1[0]['CarsLoaded']
256 : round((100 / $data1[0]['CarsLoaded']) * $data6, 2);
258 #-> Number with 2 offers
259 $query = 'SELECT priceGuide.id, COUNT(offer.id) AS numOffers '
260 . 'FROM \PriceGuide\Entity\PriceGuide priceGuide '
261 . 'JOIN priceGuide.company company '
262 . 'LEFT JOIN priceGuide.offers offer '
264 . 'GROUP BY priceGuide.id '
265 . 'HAVING numOffers = 2';
266 $query = str_replace(array(
270 ? 'WHERE ' . implode(' AND ', $where) . ' '
273 $query = $this->em->createQuery($query);
275 && $query->setParameters($params);
276 $data8 = count($query->getScalarResult());
279 #-> Number with 2 offers %
280 $data9 = 0 == $data1[0]['CarsLoaded']
282 : round((100 / $data1[0]['CarsLoaded']) * $data8, 2);
284 #-> Number with 1 offers
285 $query = 'SELECT priceGuide.id, COUNT(offer.id) AS numOffers '
286 . 'FROM \PriceGuide\Entity\PriceGuide priceGuide '
287 . 'JOIN priceGuide.company company '
288 . 'LEFT JOIN priceGuide.offers offer '
290 . 'GROUP BY priceGuide.id '
291 . 'HAVING numOffers = 1';
292 $query = str_replace(array(
296 ? 'WHERE ' . implode(' AND ', $where) . ' '
299 $query = $this->em->createQuery($query);
301 && $query->setParameters($params);
302 $data10 = count($query->getScalarResult());
305 #-> Number with 1 offers %
306 $data11 = 0 == $data1[0]['CarsLoaded']
308 : round((100 / $data1[0]['CarsLoaded']) * $data10, 2);
310 #-> Number with 0 offers
311 $query = 'SELECT priceGuide.id, COUNT(offer.id) AS numOffers '
312 . 'FROM \PriceGuide\Entity\PriceGuide priceGuide '
313 . 'JOIN priceGuide.company company '
314 . 'LEFT JOIN priceGuide.offers offer '
316 . 'GROUP BY priceGuide.id '
317 . 'HAVING numOffers = 0';
318 $query = str_replace(array(
322 ? 'WHERE ' . implode(' AND ', $where) . ' '
325 $query = $this->em->createQuery($query);
327 && $query->setParameters($params);
328 $data12 = count($query->getScalarResult());
331 #-> Number with 1 offers %
332 $data13 = 0 == $data1[0]['CarsLoaded']
334 : round((100 / $data1[0]['CarsLoaded']) * $data12, 2);
337 $data0val = $data0[0]['CarsLoaded'];
338 $data1val = $data1[0]['CarsLoaded'];
339 $data2val = $data2[0]['NumCarsWithOffers'];
340 $data4val = $data4[0]['NumOffersMade'];
342 #-> Collate information.
343 $this->_data = array(array(
344 'totalCarsLoaded' => $data0val,
345 'totalLoadedOnPg' => $data1val,
346 'TotalCarsOffers' => $data2val,
347 'TotalCarsOffersPer' => $data3,
348 'tNumOffers' => $data4val,
349 'AvgNumOffers' => $data5,
350 'NumOffers3' => $data6,
351 'NumOffers3Per' => $data7,
352 'NumOffers2' => $data8,
353 'NumOffers2Per' => $data9,
354 'NumOffers1' => $data10,
355 'NumOffers1Per' => $data11,
356 'NumOffers0' => $data12,
357 'NumOffers0Per' => $data13
359 foreach ($this->_data as $id => $row)