2 namespace Report\Report;
7 * Stock Control Report.
10 class StockAuction extends \Utility\Service\Report
18 protected $_title = 'Stock Auction Report';
22 protected $_subject = 'Stock Auction';
26 protected $_description = 'Historical report for vehicles sold on auction.';
30 protected $_notes = array(
31 'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.com.na'
36 protected $_headers = array(
55 protected $_fields = array(
62 'stock_registrationNumber',
67 'auction_reservePrice',
69 'auction_currentBidPrice',
74 protected $_totals = array(
75 'auction_currentBidPrice',
77 'auction_reservePrice',
83 protected $_currencyFields = array(
84 'auction_currentBidPrice',
86 'auction_reservePrice',
95 public function build()
97 ini_set('memory_limit','1024M');
98 #-> Prepare parameters.
100 'auction', 'stock', 'type', 'year', 'make',
101 'buyerCompany', 'buyerGroup', 'buyerDivision'
107 $query = 'SELECT [SELECTION] '
108 . 'FROM \Auction\Entity\Auction auction '
109 . ' JOIN auction.stock stock '
110 . ' JOIN stock.company sellerCompany '
111 . ' JOIN auction.bids bid '
112 . ' LEFT JOIN stock.type type '
113 . ' LEFT JOIN stock.vehicleYear year '
114 . ' LEFT JOIN type.model model '
115 . ' LEFT JOIN model.make make '
116 . ' LEFT JOIN auction.createdBy sellerProfile '
117 . ' LEFT JOIN auction.currentBid currentBid '
118 . ' LEFT JOIN currentBid.profile buyerProfile '
119 . ' LEFT JOIN currentBid.company buyerCompany '
120 . ' LEFT JOIN sellerCompany.group sellerGroup '
121 . ' LEFT JOIN sellerCompany.groupDivision sellerDivision '
122 . ' LEFT JOIN buyerProfile.group buyerGroup '
123 . ' LEFT JOIN buyerProfile.groupDivision buyerDivision '
125 . 'GROUP BY auction.id '
126 . 'ORDER BY auction.created ASC';
127 $where[] = 'auction.jobState = \'Sold\'';
129 #-> Construct details.
130 $authData = \Utility\Registry::getAuthData();
131 if (isset($this->_input['dateFrom']) && !empty($this->_input['dateFrom']))
133 $this->_queries['Date Range From'] = $this->_input['dateFrom'];
134 $where[] = 'auction.endDate >= :dateFrom';
135 $params['dateFrom'] = new \DateTime($this->_input['dateFrom']);
137 if (isset($this->_input['dateTo']) && !empty($this->_input['dateTo']))
139 $this->_queries['Date Range Until'] = $this->_input['dateTo'];
140 $where[] = 'auction.endDate <= :dateTo';
141 $params['dateTo'] = new \DateTime($this->_input['dateTo'] . ' 23:59:59');
143 if (isset($this->_input['group'])
144 && !empty($this->_input['group'])
145 && 'null' != $this->_input['group'])
147 $this->_queries['Group'] = $this->em
148 ->find('\Company\Entity\Group', $this->_input['group'])
150 $where[] = 'sellerGroup.id = :group';
151 $params['group'] = $this->_input['group'];
153 if (isset($this->_input['groupDivision'])
154 && !empty($this->_input['groupDivision'])
155 && 'null' != $this->_input['groupDivision'])
157 error_log($this->_input['groupDivision']);
158 $this->_queries['Division'] = $this->em
159 ->find('\Company\Entity\GroupDivision', $this->_input['groupDivision'])
161 $where[] = 'sellerDivision.id = :division';
162 $params['division'] = $this->_input['groupDivision'];
164 if (isset($this->_input['company'])
165 && !empty($this->_input['company'])
166 && 'null' != $this->_input['company'])
168 $this->_queries['Dealership'] = $this->em
169 ->find('\Company\Entity\Company', $this->_input['company'])
171 $where[] = 'sellerCompany.id = :company';
172 $params['company'] = $this->_input['company'];
176 $query = str_replace(array(
177 '[SELECTION]', '[WHERE]'
179 implode(', ', $selection) . ' ',
181 ? 'WHERE ' . implode(' AND ', $where) . ' '
186 $query = $this->em->createQuery($query);
188 && $query->setParameters($params);
190 $this->_data = $query->getScalarResult();
193 // foreach ($this->_data as $id => $row)
195 // $this->_data[$id]['bidPerc'] = 0 < $row['stock_tradePrice']
196 // ? round((100 / $row['stock_tradePrice']) * $row['auction_currentBidPrice'], 1) . ' %'