2 namespace Stock\Report;
7 * Stock Contyrol Report.
10 class StockControl extends \Utility\Service\Report
18 protected $_title = 'Stock Control Report';
22 protected $_subject = 'Vehicles in stock.';
26 protected $_description = 'Historical report for vehicles in stock.';
30 protected $_notes = array(
31 'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.com.na'
36 protected $_headers = array(
42 'Registration Number',
45 'Price Guide Highest Offer',
46 'Retail Amount Required',
50 'Sales Person Surname'
55 protected $_fields = array(
56 'stock_referenceNumber',
61 'stock_registrationNumber',
63 'valuation_amountOffered',
65 'stock_retailAmountRequired',
75 protected $_totals = array(
83 protected $_currencyFields = array(
84 'valuation_amountOffered',
86 'stock_retailAmountRequired',
97 public function build()
99 #-> Prepare parameters.
101 'stock', 'type', 'model', 'make', 'valuation', 'sales'
107 $query = 'SELECT [SELECTION] '
108 . 'FROM \Stock\Entity\Stock stock '
109 . ' JOIN stock.type type '
110 . ' JOIN type.model model '
111 . ' JOIN model.make make '
113 . ' LEFT JOIN stock.valuation valuation '
114 . ' LEFT JOIN valuation.salesProfile sales '
117 . 'ORDER BY stock.created';
119 #-> Construct details.
120 $authData = \Utility\Registry::getAuthData();
121 switch (\Utility\Registry::getUserType())
124 $groupFilter = \Utility\Registry::getSudo('Group', false);
127 $this->_queries['Group'] = \Utility\Registry::getSudo('GroupName');
128 $join[] = 'JOIN stock.company company';
129 $where[] = 'IDENTITY(company.group) = :group';
130 $params['group'] = $groupFilter;
132 $divisionFilter = \Utility\Registry::getSudo('Division', false);
135 $this->_queries['Division'] = \Utility\Registry::getSudo('DivisionName');
136 $join[] = 'JOIN stock.company company';
137 $where[] = 'IDENTITY(company.groupDivision) = :groupDivision';
138 $params['groupDivision'] = $divisionFilter;
140 $companyFilter = \Utility\Registry::getSudo('Company', false);
143 $this->_queries['Company'] = \Utility\Registry::getSudo('CompanyName');
144 $where[] = 'IDENTITY(stock.company) = :company';
145 $params['company'] = $companyFilter;
149 $join[] = 'JOIN stock.company company';
150 $where[] = 'IDENTITY(company.group) = :group';
151 $params['group'] = $authData['company']['group']['id'];
152 $divisionFilter = \Utility\Registry::getSudo('Division', false);
155 $this->_queries['Division'] = \Utility\Registry::getSudo('DivisionName');
156 $join[] = 'JOIN stock.company company';
157 $where[] = 'IDENTITY(company.groupDivision) = :groupDivision';
158 $params['groupDivision'] = $divisionFilter;
160 $companyFilter = \Utility\Registry::getSudo('Company', false);
163 $this->_queries['Company'] = \Utility\Registry::getSudo('CompanyName');
164 $where[] = 'IDENTITY(stock.company) = :company';
165 $params['company'] = $companyFilter;
168 case 'Dealer Principle':
169 $join[] = 'JOIN stock.company company';
170 $where[] = 'IDENTITY(company.groupDivision) = :groupDivision';
171 $params['groupDivision'] = $authData['company']['groupDivision']['id'];
172 $companyFilter = \Utility\Registry::getSudo('Company', false);
175 $this->_queries['Company'] = \Utility\Registry::getSudo('CompanyName');
176 $where[] = 'IDENTITY(stock.company) = :company';
177 $params['company'] = $companyFilter;
181 $where[] = 'IDENTITY(stock.company) = :company';
182 $params['company'] = $authData['company']['id'];
185 if (isset($this->_input['jobState']))
187 $this->_queries['Status'] = $this->_input['jobState'];
188 $where[] = 'stock.jobState >= :jobState';
189 $params['jobState'] = $this->_input['jobState'];
191 if (isset($this->_input['dateFrom']))
193 $this->_queries['Date Range From'] = $this->_input['dateFrom'];
194 $where[] = 'stock.created >= :dateFrom';
195 $params['dateFrom'] = new \DateTime($this->_input['dateFrom']);
197 if (isset($this->_input['dateTo']))
199 $this->_queries['Date Range Until'] = $this->_input['dateTo'];
200 $where[] = 'stock.created <= :dateTo';
201 $params['dateTo'] = new \DateTime($this->_input['dateTo']);
205 $query = str_replace(array(
206 '[SELECTION]', '[JOIN]', '[LEFT-JOIN]', '[WHERE]'
208 implode(', ', $selection) . ' ',
209 implode(' ', $join) . ' ',
210 implode(' ', $leftJion) . ' ',
212 ? 'WHERE ' . implode(' AND ', $where) . ' '
217 $query = $this->em->createQuery($query);
219 && $query->setParameters($params);
220 $this->_data = $query->getScalarResult();