initial commit
[namibia] / module / PriceGuide / src / PriceGuide / Report / PriceGuideGrid.php
1 <?php
2 namespace PriceGuide\Report;
3
4
5
6 /**
7  * Stock Control Report.
8  * @author andre.fourie
9  */
10 class PriceGuideGrid extends \Utility\Service\Report
11 {
12
13
14
15         /**
16          * @var string
17          */
18         protected $_title  = 'Price Guide Data Export';
19         /**
20          * @var string
21          */
22         protected $_subject = 'Vehicles on price guide.';
23         /**
24          * @var string
25          */
26         protected $_description = 'Export of vehicles available on price guide.';
27         /**
28          * @var array
29          */
30         protected $_notes = array(
31                         'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.co.za'
32                         );
33         /**
34          * @var array
35          */
36         protected $_headers = array(
37                         'Seller',
38                         'Group',
39                         'Division',
40                         'Region',
41                         'Reference Number',
42                         'Registration Number',
43                         'VIN Number',
44                         'Make',
45                         'Model',
46                         'Type',
47                         'Year',
48                         'Main Exterior Colour',
49                         'KM',
50                         'Trade Price',
51                         'Retail Price',
52                         'Number of price guide offers',
53                         'Highest price guide offer',
54                         'My offer',
55                         'Status',
56                         'Created',
57                         'Updated'
58                         );
59         /**
60          * @var array
61          */
62         protected $_fields = array(
63                         'company_name',
64                         'companyGroup_name',
65                         'groupDivision_name',
66                         'region_name',
67                         'stock_referenceNumber',
68                         'stock_registrationNumber',
69                         'stock_vinNumber',
70                         'make_name',
71                         'model_name',
72                         'type_name',
73                         'vehicleYear_name',
74                         'exteriorColour_name',
75                         'stock_km',
76                         'stock_tradePrice',
77                         'stock_retailPrice',
78             'stock_listPrice',
79                         'stock_numberOfOffers',
80                         'stock_highestOffer',
81                         'priceGuide_id',
82                         'priceGuide_jobState',
83                         'priceGuide_created',
84                         'priceGuide_updated'
85                         );
86         /**
87          * @var array
88          */
89         protected $_totals = array(
90                         'stock_tradePrice',
91                         'stock_retailPrice',
92             'stock_listPrice',
93                         'stock_retailAmountRequired',
94                         'stock_highestOffer',
95                         'priceGuide_id'
96                         );
97         /**
98          * @var array
99          */
100         protected $_currencyFields = array(
101                         'stock_tradePrice',
102                         'stock_retailPrice',
103             'stock_listPrice',
104                         'stock_retailAmountRequired',
105                         'stock_highestOffer',
106                         'priceGuide_id'
107                         );
108
109
110
111         /**
112          * Build the dataset, or not.
113          */
114         public function build()
115         {
116                 #-> Data passed by DataBin Grid functionality.
117                 $dateTimeFormat = \Utility\Definitions\Locale::getDateTimeFormat();
118                 $auth = \Utility\Registry::getAuthData();
119                 foreach ($this->_data as $rowId => $rowData)
120                 {
121                         $myOffer = $this->em->getRepository('\PriceGuide\Entity\Offer')
122                                 ->findOneBy(array(
123                                         'priceGuideStock' => $this->_data[$rowId]['priceGuide_id'],
124                                         'company' => $auth['company']['id']
125                                 ));
126                         $this->_data[$rowId]['priceGuide_id'] = is_object($myOffer)
127                                 ? $myOffer->amount
128                                 : 0.0;
129                         $this->em->clear('\PriceGuide\Entity\Offer');
130                         $this->_data[$rowId]['priceGuide_created'] = $rowData['priceGuide_created']->format($dateTimeFormat);
131                         $this->_data[$rowId]['priceGuide_updated'] = !is_null($rowData['priceGuide_updated'])
132                                 ? $rowData['priceGuide_updated']->format($dateTimeFormat)
133                                 : '';
134                         if ('Updateable Offers' == $this->_data[$rowId]['priceGuide_jobState'] || 'Open4Offers' == $this->_data[$rowId]['priceGuide_jobState'])
135                         {
136                                 $this->_data[$rowId]['stock_highestOffer'] = 0.0;
137                         }
138                 }
139         }
140
141 }