initial commit
[namibia] / module / Retail / src / Retail / Service / RetailService.php
1 <?php
2 namespace Retail\Service;
3
4 class RetailService
5 {
6         /**
7          * Return Hello World!
8          * @return string
9          */
10         public function hello()
11         {
12                 return "Hello world!";
13         }
14
15         /**
16          * Return Hello whatever
17          * @param string $name
18          * @return string
19          */
20         public function helloBob($name)
21         {
22                 return "Hello " . (string) $name;
23         }
24
25         /**
26          * Return all retail data for a given retailer based on their authtoken.
27          * @param string $authToken
28          * @return array
29          */
30         public function getVehicleListing($authToken)
31         {
32                 $dataSet = \Utility\Registry::getEntityManager()
33                         ->createQuery(
34                                           'SELECT stock, company, retailers, type, model, make, fuelType, transmissionType,'
35                                         . ' exteriorColour, interiorColour, condition, vehicleYear, upholstery,'
36                                         . ' papers, natis, fsh, introYear, discYear,'
37                                         . ' mainImage, frontImage, rightImage, leftImage,'
38                                         . ' backImage, interiorImage, engineImage, natisImage,'
39                                         . ' accessories, accessory, damages, damage '
40                                         . 'FROM \Stock\Entity\Stock stock '
41                                         . 'JOIN stock.company company '
42                                         . 'JOIN company.retailers retailers '
43                                         . 'JOIN retailers.retail retail '
44                                         . 'JOIN stock.type type '
45                                         . 'JOIN type.model model '
46                                         . 'JOIN model.make make '
47                                         . 'LEFT JOIN type.introYear introYear '
48                                         . 'LEFT JOIN type.discYear discYear '
49                                         . 'LEFT JOIN stock.fuelType fuelType '
50                                         . 'LEFT JOIN stock.transmissionType transmissionType '
51                                         . 'LEFT JOIN stock.exteriorColour exteriorColour '
52                                         . 'LEFT JOIN stock.interiorColour interiorColour '
53                                         . 'LEFT JOIN stock.condition condition '
54                                         . 'LEFT JOIN stock.vehicleYear vehicleYear '
55                                         . 'LEFT JOIN stock.upholstery upholstery '
56                                         . 'LEFT JOIN stock.papers papers '
57                                         . 'LEFT JOIN stock.natis natis '
58                                         . 'LEFT JOIN stock.fullServiceHistory fsh '
59                                         . 'LEFT JOIN stock.mainImage mainImage '
60                                         . 'LEFT JOIN stock.frontImage frontImage '
61                                         . 'LEFT JOIN stock.rightImage rightImage '
62                                         . 'LEFT JOIN stock.leftImage leftImage '
63                                         . 'LEFT JOIN stock.backImage backImage '
64                                         . 'LEFT JOIN stock.interiorImage interiorImage '
65                                         . 'LEFT JOIN stock.engineImage engineImage '
66                                         . 'LEFT JOIN stock.natisImage natisImage '
67                                         . 'LEFT JOIN stock.accessories accessories '
68                                         . 'LEFT JOIN accessories.accessory accessory '
69                                         . 'LEFT JOIN stock.damages damages '
70                                         . 'LEFT JOIN damages.damage damage '
71                                         . 'WHERE stock.jobState=\'Retail\' '
72                                         . ' AND retail.authToken = \'' . addslashes($authToken) . '\' '
73                                         . ' AND stock.archived = 0'
74                                         . ' AND company.archived = 0'
75                                         . ' AND retailers.archived = 0'
76                         )
77                         ->getArrayResult();
78                 $data = array();
79                 $imgUrl = \Utility\Registry::getConfigParam('Host') . '/img/bin/';
80                 foreach ($dataSet as $row)
81                 {
82                         \Utility\Debug::errorLog('DATA for XMLRPC api', $row);
83                         $accessories = array();
84                         foreach ($row['accessories'] as $acc)
85                         {
86                                 $accessories[] = $acc['accessory']['name'];
87                         }
88                         $damages = array();
89                         foreach ($row['damages'] as $dmg)
90                         {
91                                 $damages[] = array(
92                                                 'component'             => null,
93                                                 'part'                          => null,
94                                                 'type'                          => $dmg['damage']['name'],
95                                                 'estimated_repair'      => $dmg['amount'],
96                                                 'photo_url'                     => false
97                                 );
98                         }
99                         $data[] = array(
100                                 'id'                                                    => $row['id'],
101                                 'registration_number'                   => $row['registrationNumber'],
102                                 'vehicle_year'                                  => $row['vehicleYear']['name'],
103                                 'stock_number'                                  => $row['stockNumber'],
104                                 'km'                                                    => $row['km'],
105                                 'specific_color'                                => !is_null($row['exteriorColour'])
106                                                                                                         ? $row['exteriorColour']['name']
107                                                                                                         : null,
108                                 'vin_number'                                    => $row['vinNumber'],
109                                 'engine_number'                                 => $row['engineNumber'],
110                                 'full_service_history_notes'    => $row['fshNotes'],
111                                 'mm_code'                                               => $row['type']['mmCode'],
112                                 'stand_in_value'                                => null,
113                                 'reserve_price'                                 => $row['retailAmountRequired'],
114                                 'remarks'                                               => '',
115                                 'faults_explenation'                    => '',
116                                 'previous_repair_notes'                 => $row['previousRepairsNotes'],
117                                 'accessory_remarks'                     => $row['accessoryNotes'],
118                                 'dealer_retail_account_no'              => $row['company']['retailers'][0]['username'],
119                                 'main_photo_url'                                => !is_null($row['mainImage'])
120                                                                                                         ? $imgUrl . $row['mainImage']['filename']
121                                                                                                         : false,
122                                 'first_additional_photo_url'    => !is_null($row['frontImage'])
123                                                                                                         ? $imgUrl . $row['frontImage']['filename']
124                                                                                                         : false,
125                                 'second_additional_photo_url'   => !is_null($row['rightImage'])
126                                                                                                         ? $imgUrl . $row['rightImage']['filename']
127                                                                                                         : false,
128                                 'third_additional_photo_url'    => !is_null($row['leftImage'])
129                                                                                                         ? $imgUrl . $row['leftImage']['filename']
130                                                                                                         : false,
131                                 'fourth_additional_photo_url'   => !is_null($row['backImage'])
132                                                                                                         ? $imgUrl . $row['backImage']['filename']
133                                                                                                         : false,
134                                 'fifth_additional_photo_url'    => !is_null($row['interiorImage'])
135                                                                                                         ? $imgUrl . $row['interiorImage']['filename']
136                                                                                                         : false,
137                                 'sixth_additional_photo_url'    => !is_null($row['engineImage'])
138                                                                                                         ? $imgUrl . $row['engineImage']['filename']
139                                                                                                         : false,
140                                 'seventh_additional_photo_url'  => !is_null($row['natisImage'])
141                                                                                                         ? $imgUrl . $row['natisImage']['filename']
142                                                                                                         : false,
143                                 'full_service_history'                  => !is_null($row['fullServiceHistory'])
144                                                                                                         ? $row['fullServiceHistory']['name']
145                                                                                                         : '',
146                                 'vehicle_spare_key'                     => is_null($row['spareKeys'])
147                                                                                                         ? null
148                                                                                                         : ($row['spareKeys'] ? true : false),
149                                 'vehicle_paper'                                 => !is_null($row['papers'])
150                                                                                                         ? $row['papers']['name']
151                                                                                                         : null,
152                                 'condition'                                     => !is_null($row['condition'])
153                                                                                                         ? $row['condition']['name']
154                                                                                                         : null,
155                                 'make'                                                  => $row['type']['model']['make']['name'],
156                                 'model'                                                 => $row['type']['model']['name'],
157                                 'type'                                                  => $row['type']['name'],
158                                 'base_color'                                    => !is_null($row['exteriorColour'])
159                                                                                                         ? $row['exteriorColour']['name']
160                                                                                                         : null,
161                                 'interior'                                              => !is_null($row['upholstery'])
162                                                                                                         ? $row['upholstery']['name']
163                                                                                                         : null,
164                                 'interior_color'                                => !is_null($row['interiorColour'])
165                                                                                                         ? $row['interiorColour']['name']
166                                                                                                         : null,
167                                 'natis'                                                 => !is_null($row['natis'])
168                                                                                                         ? $row['natis']['name']
169                                                                                                         : null,
170                                 'vehicle_intro_year'                    => !is_null($row['type']['introYear'])
171                                                                                                         ? $row['type']['introYear']['name']
172                                                                                                         : null,
173                                 'vehicle_intro_month'                   => $row['type']['introMonth'],
174                                 'vehicle_disc_year'                     => !is_null($row['type']['discYear'])
175                                                                                                         ? $row['type']['discYear']['name']
176                                                                                                         : null,
177                                 'vehicle_disc_month'                    => $row['type']['discMonth'],
178                                 'vehicle_cyl'                                   => $row['type']['cylinders'],
179                                 'vehicle_cubic_capacity'                => $row['type']['cubicCapacity'],
180                                 'vehicle_kilowatts'                     => $row['type']['kilowatts'],
181                                 'vehicle_body_type'                     => $row['type']['bodyType'],
182                                 'vehicle_number_of_doors'               => $row['type']['doors'],
183                                 'fuel_type'                                     => !is_null($row['fuelType'])
184                                                                                                         ? $row['fuelType']['name']
185                                                                                                         : null,
186                                 'transmission_type'                     => !is_null($row['transmissionType'])
187                                                                                                         ? $row['transmissionType']['name']
188                                                                                                         : null,
189                                 'accessories'                                   => $accessories,
190                                 'damages'                                               => $damages
191                         );
192                 }
193                 return $data;
194         }
195 }