2 namespace Report\Report;
10 class TuhpiLog extends \Utility\Service\Report
18 protected $_title = 'HPI Log Report';
22 protected $_subject = 'HPI';
26 protected $_description = 'Historical report for HPI report requests.';
30 protected $_notes = array(
31 'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.com.na'
36 protected $_headers = array(
56 protected $_fields = array(
58 'companyDivision_name',
64 'stock_registrationNumber',
70 'tuhpi_transactionNumber',
76 protected $_totals = array();
80 protected $_currencyFields = array();
87 public function build()
89 #-> Prepare parameters.
91 'log', 'tuhpi', 'stock', 'type', 'model', 'make',
92 'company', 'companyGroup', 'companyDivision', 'profile'
98 $query = 'SELECT [SELECTION] '
99 . 'FROM \Stock\Entity\TuhpiLog log '
100 . ' JOIN log.stock stock '
101 . ' JOIN log.company company '
102 . ' JOIN log.createdBy profile '
103 . ' LEFT JOIN log.tuhpi tuhpi '
104 . ' LEFT JOIN stock.type type '
105 . ' LEFT JOIN type.model model '
106 . ' LEFT JOIN model.make make '
107 . ' LEFT JOIN company.group companyGroup '
108 . ' LEFT JOIN company.groupDivision companyDivision '
110 . 'ORDER BY log.created ASC';
112 $where[] = ' (tuhpi.hpi_type is null OR tuhpi.hpi_type = :hpiType) ';
113 $params['hpiType'] = 'HPI';
115 #-> Construct details.
116 $authData = \Utility\Registry::getAuthData();
117 if (isset($this->_input['dateFrom']) && !empty($this->_input['dateFrom']))
119 $this->_queries['Date Range From'] = $this->_input['dateFrom'];
120 $where[] = 'log.created >= :dateFrom';
121 $params['dateFrom'] = new \DateTime($this->_input['dateFrom']);
123 if (isset($this->_input['dateTo']) && !empty($this->_input['dateTo']))
125 $this->_queries['Date Range Until'] = $this->_input['dateTo'];
126 $where[] = 'log.created <= :dateTo';
127 $params['dateTo'] = new \DateTime($this->_input['dateTo'] . ' 23:59:59');
129 if (isset($this->_input['group'])
130 && !empty($this->_input['group'])
131 && 'null' != $this->_input['group'])
133 $this->_queries['Group'] = $this->em
134 ->find('\Company\Entity\Group', $this->_input['group'])
136 $where[] = 'companyGroup.id = :group';
137 $params['group'] = $this->_input['group'];
139 if (isset($this->_input['groupDivision'])
140 && !empty($this->_input['groupDivision'])
141 && 'null' != $this->_input['groupDivision'])
143 // error_log($this->_input['groupDivision']);
144 $this->_queries['Division'] = $this->em
145 ->find('\Company\Entity\GroupDivision', $this->_input['groupDivision'])
147 $where[] = 'companyDivision.id = :division';
148 $params['division'] = $this->_input['groupDivision'];
150 if (isset($this->_input['company'])
151 && !empty($this->_input['company'])
152 && 'null' != $this->_input['company'])
154 $this->_queries['Dealership'] = $this->em
155 ->find('\Company\Entity\Company', $this->_input['company'])
157 $where[] = 'company.id = :company';
158 $params['company'] = $this->_input['company'];
162 $query = str_replace(array(
163 '[SELECTION]', '[WHERE]'
165 implode(', ', $selection) . ' ',
167 ? 'WHERE ' . implode(' AND ', $where) . ' '
172 $query = $this->em->createQuery($query);
174 && $query->setParameters($params);
176 // \Utility\Debug::errorLog('$query->getSQL()', $query->getSQL());
177 // \Utility\Debug::errorLog('$query->getParameters()', $query->getParameters());
180 // \Utility\Debug::errorLog('$query->getScalarResult()', $query->getScalarResult());
182 $this->_data = $query->getScalarResult();