2 namespace Valuation\Report;
7 * Stock Contyrol Report.
10 class ValuationGrid extends \Utility\Service\Report
18 protected $_title = 'Valuation Data Export';
22 protected $_subject = 'Valuations';
26 protected $_description = 'Export of valuations.';
30 protected $_notes = array(
31 'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.co.za'
36 protected $_headers = array(
41 'Registration Number',
48 'Main Exterior Colour',
52 'Price Offered to Sales',
54 'Date loaded on price guide',
55 'Number of price guide offers',
56 'Highest price guide offer',
57 'Highest price Dealer Name(s)',
65 protected $_fields = array(
69 'stock_referenceNumber',
70 'stock_registrationNumber',
77 'exteriorColour_name',
81 'valuation_amountOffered',
83 'stock_loadedOnPriceGuide',
84 'stock_numberOfOffers',
88 'salesProfile_fullName',
89 'managerProfile_fullName'
94 protected $_totals = array(
105 protected $_currencyFields = array(
110 'stock_highestOffer',
111 'valuation_amountOffered'
119 public function build()
121 #-> Data passed by DataBin Grid functionality.
123 ini_set('memory_limit','512M');
124 foreach ($this->_data as $rowId => $rowData)
126 $this->_data[$rowId]['salesProfile_fullName'] = isset($rowData['salesProfile_firstName'])
127 && !empty($rowData['salesProfile_firstName'])
128 ? $rowData['salesProfile_firstName'] . ' ' . $rowData['salesProfile_familyName']
130 $this->_data[$rowId]['managerProfile_fullName'] = isset($rowData['managerProfile_firstName'])
131 && !empty($rowData['managerProfile_firstName'])
132 ? $rowData['managerProfile_firstName'] . ' ' . $rowData['managerProfile_familyName']
134 if (is_null($rowData['priceGuide_id']))
136 $this->_data[$rowId]['higestoffernames'] = '';
139 $query = 'SELECT priceGuideOffer, company '
140 . 'FROM \PriceGuide\Entity\Offer priceGuideOffer '
141 . 'JOIN priceGuideOffer.company company '
142 . 'WHERE IDENTITY(priceGuideOffer.priceGuideStock) = :priceGuideId'
143 . ' AND priceGuideOffer.amount = :highestOffer';
144 $query = $this->em->createQuery($query);
145 $query->setParameter('priceGuideId', $rowData['priceGuide_id']);
146 $query->setParameter('highestOffer', $rowData['stock_highestOffer']);
147 $resultx = $query->getArrayResult();
151 $this->_data[$rowId]['higestoffernames'] = '';
155 foreach($resultx as $itemx)
157 $dealers[] = $itemx['company']['name'];
159 $this->_data[$rowId]['higestoffernames'] = implode(', ', $dealers);
163 foreach ($this->_data as $rowId => $rowData)
165 if ($this->_data[$rowId]['stock_tradePrice'] == 0)
167 $this->_data[$rowId]['valuation_updated'] = '0 %';
171 $this->_data[$rowId]['valuation_updated'] = round(($this->_data[$rowId]['valuation_amountOffered'] * 100) / $this->_data[$rowId]['stock_tradePrice']) . ' %' ;