2 namespace PriceGuide\DataBin;
7 * Manage PriceGuide data.
10 class PriceGuide extends \Workspace\Service\DataBin
16 protected $meta = array(
17 'Base' => 'PriceGuide',
18 'DatasetName' => 'valuations',
19 'Entity' => '\PriceGuide\Entity\PriceGuide',
20 'References' => array(
21 'valuation' => '\Valuation\Entity\Valuation',
22 'stock' => '\Stock\Entity\Stock',
23 'createdBy' => '\User\Entity\Profile',
24 'company' => '\Company\Entity\Company'
26 'Dependants' => array()
31 protected $metaGrid = array(
34 'Builder' => '\PriceGuide\Report\PriceGuideGrid',
35 'Writer' => '\Utility\Export\ExcelReport',
36 'Output' => 'Download',
37 'Contract' => 'Recurring',
40 'ExportToExcel' => false
43 'RequiredInput' => array(),
44 'OptionalInput' => array(
46 'NumberOfRecords' => 'Integer',
52 'Base' => 'priceGuide',
53 'NumberOfRecords' => 20,
54 'Query' => 'SELECT [SELECTION]
55 FROM \PriceGuide\Entity\PriceGuide priceGuide
56 JOIN priceGuide.members members
57 JOIN members.member mmbr
58 JOIN mmbr.company memberCompany
59 JOIN priceGuide.company company
60 JOIN company.region region
61 JOIN priceGuide.stock stock
62 JOIN stock.vehicleYear vehicleYear
66 LEFT JOIN company.group companyGroup
67 LEFT JOIN company.groupDivision groupDivision
68 LEFT JOIN stock.exteriorColour exteriorColour
69 LEFT JOIN priceGuide.offers offer WITH IDENTITY(offer.company) = [company]
70 LEFT JOIN offer.company offercompany
71 LEFT JOIN stock.valuation valuation
73 'Selection' => 'priceGuide, mmbr, company, companyGroup, groupDivision, region, stock, vehicleYear, make, model, type, exteriorColour, offer, offercompany, valuation',
75 'mmbr.status' => 'Active',
76 'statusFilter' => array(
77 'priceGuide.jobState' => 'IN Open4Offers,Updateable Offers',
80 'priceGuide.archived' => 0
82 'OrderBy' => array('priceGuide.created' => 'DESC'),
85 'created' => 'DateTime',
86 'updated' => 'DateTime',
88 'offers' => array(array(
92 'created' => 'DateTime',
105 'created' => 'DateTime',
115 'vehicleYear' => array(
118 'exteriorColour' => array(
127 'valuation' => array(
136 protected $metaView = array(
138 'Contract' => 'Recurring',
163 'fullServiceHistory',
173 'RequiredInput' => array(),
174 'OptionalInput' => array()
179 protected $metaCreate = array(
181 'Contract' => 'Recurring',
182 'ExecuteAfter' => array(
185 'RequiredInput' => array(
186 'PriceGuide' => array(
191 'OptionalInput' => array()
196 protected $metaUpdate = array(
198 'Contract' => 'UseOnce',
199 'RequiredInput' => array(
200 'PriceGuide' => array(
205 'OptionalInput' => array()
210 protected $metaSendToSales = array(
212 'Contract' => 'UseOnce',
213 'ConditionalContract' => array(
214 'noSendToSalesWithoutValuation'
216 'ExecuteAfter' => array(
217 'setPreviousStateToComplete'
219 'RelatedEntityFromInput' => array(
220 'Valuation' => array(
221 'Workflow' => '\Valuation\Workflow',
222 'Service' => '\Valuation\Service\Valuation',
223 'Field' => 'valuation'
226 'RequiredInput' => array(
227 'Valuation' => array(
228 'amountOffered' => 'Decimal',
229 'salesProfile' => 'Id'
232 'OptionalInput' => array(
233 'Valuation' => array(
234 'salesComments' => 'String500'
242 * Add some dynamic filtering to our grids.
244 public function __construct()
246 $authData = \Utility\Registry::getAuthData();
247 switch (\Utility\Registry::getUserType())
250 $groupFilter = \Utility\Registry::getSudo('Group', false);
252 && $this->metaGrid['Filter']['IDENTITY(memberCompany.group)'] = $groupFilter;
253 $divisionFilter = \Utility\Registry::getSudo('Division', false);
255 && $this->metaGrid['Filter']['IDENTITY(memberCompany.groupDivision)'] = $divisionFilter;
256 $companyFilter = \Utility\Registry::getSudo('Company', false);
257 if ($groupFilter && $divisionFilter && $companyFilter)
259 $this->metaGrid['Filter']['memberCompany.id'] = $companyFilter;
260 $this->metaGrid['Query'] = str_replace(
261 '[company]', $companyFilter, $this->metaGrid['Query']
266 $this->metaGrid['Query'] = str_replace(
267 '[company]', '0', $this->metaGrid['Query']
272 $this->metaGrid['Filter']['IDENTITY(memberCompany.group)'] = $authData['company']['group']['id'];
273 $divisionFilter = \Utility\Registry::getSudo('Division', false);
275 && $this->metaGrid['Filter']['IDENTITY(memberCompany.groupDivision)'] = $divisionFilter;
276 $companyFilter = \Utility\Registry::getSudo('Company', false);
277 if ($divisionFilter && $companyFilter)
279 $this->metaGrid['Filter']['memberCompany.id'] = $companyFilter;
280 $this->metaGrid['Query'] = str_replace(
281 '[company]', $companyFilter, $this->metaGrid['Query']
286 $this->metaGrid['Query'] = str_replace(
287 '[company]', '0', $this->metaGrid['Query']
291 case 'Dealer Principle':
292 $this->metaGrid['Filter']['IDENTITY(memberCompany.groupDivision)'] = $authData['company']['groupDivision']['id'];
293 $companyFilter = \Utility\Registry::getSudo('Company', false);
296 $this->metaGrid['Filter']['memberCompany.id'] = $companyFilter;
297 $this->metaGrid['Query'] = str_replace(
298 '[company]', $companyFilter, $this->metaGrid['Query']
303 $this->metaGrid['Query'] = str_replace(
304 '[company]', '0', $this->metaGrid['Query']
309 $this->metaGrid['Filter']['memberCompany.id'] = $authData['company']['id'];
310 $this->metaGrid['Query'] = str_replace(
311 '[company]', $authData['company']['id'], $this->metaGrid['Query']