· 8 years ago · Jun 04, 2018, 01:22 PM
1<?php
2/**
3*
4* File generato automaticamente
5*
6* @author ClassGenerator by [MF]
7* @version $Id: DeliveryagendaController.class.php,v 1.19 2018/06/01 19:17:55 alessandra Exp $
8* ------------------------------------------------------------------------
9*/
10namespace Deliveryagenda\controllers;
11
12require_once (DOCUMENT_ROOT . '/classes/PController.class.php');
13require_once (DOCUMENT_ROOT . '/appl/Deliveryagenda/controllers/AjaxRequestController.class.php');
14require_once (DOCUMENT_ROOT . '/classes/DeliveryAgenda.class.php');
15require_once (DOCUMENT_ROOT . '/classes/Agenda.class.php');
16require_once ('classes/MarketParams.class.php');
17require_once APPL_PATH . 'COMMON/classes/Prenotation.class.php';
18require_once(APPL_PATH . 'COMMON/ConfiguratorEngine/OptionalData/controller/OptionalDataController.class.php');
19require_once APPL_PATH . 'COMMON/classes/CommercialVehicle.class.php';
20require_once (APPL_PATH . 'COMMON/classes/StoreContact.class.php');
21
22use Deliveryagenda\controllers\AjaxRequestController;
23
24class DeliveryagendaController extends \PController {
25
26 private static $EMAIL_BODY = 8;
27
28 public $entry;
29 public $module;
30 public $panel;
31 public $box;
32 public $roles;
33 public $title;
34
35 /**
36 * List of setters properties
37 */
38
39 public function __construct ()
40 {
41 $this->title = 'Deliveryagenda';
42 $this->panel = array();
43 $this->box = array();
44 }
45
46 public function showHeader()
47 {
48 return true;
49 }
50
51 public function showWelcome()
52 {
53 return true;
54 }
55
56 public function showMenu()
57 {
58 w_require_widget('menu');
59 $menu = new \Menu_Widget();
60 $menu->getExpanded();
61 return true;
62 }
63
64 // The process function is the minimum required.
65 public function process()
66 {
67 // Do processing
68 switch ($this->entry) {
69
70 case 'ajaxRequest': {
71
72 header("Content-type: application/json");
73
74 $result = AjaxRequestController::doAjaxQuery($this, $this->module);
75 $this->displayAjax($result);
76 }
77 break;
78
79 default: {
80
81 $this->requiredHeaders = DOCUMENT_ROOT.'/appl/Deliveryagenda/views/headers.tpl.php';
82 $this->requiredBox['LEFT']['2'] = DOCUMENT_ROOT.'/appl/Deliveryagenda/views/content.tpl.php';
83 //$this->requiredBox['RIGHT']['1'] = DOCUMENT_ROOT.'/appl/CRM/contacts/view/CRM_search_contacts.tpl.php';
84 $this->requiredBox['RIGHT']['1'] = DOCUMENT_ROOT.'/appl/Deliveryagenda/views/search_contacts.tpl.php';
85 //$this->requiredBox['RIGHT']['3'] = DOCUMENT_ROOT.'/appl/Deliveryagenda/views/widget.tpl.php';
86
87 $this->tpl = DOCUMENT_ROOT.'/appl/templates/main.tpl.php';
88 }
89 break;
90 }
91 $this->display();
92 }
93
94 /** getStockDataByVin
95 *
96 * @param array $data
97 * @param array $tokenproperties
98 * @throws \Exception
99 * @return \StockDealerCollection
100 */
101 public function getStockDataByVin($data, $tokenproperties)
102 {
103 $p_codmarket = $tokenproperties['CODMARKET'];
104 $p_coddealer = $tokenproperties['CODDEALER'];
105 $p_codlanguage = $tokenproperties['CODLANGUAGE'];
106 $p_codmodel = isset($data['codmodel']) ? strtoupper(trim($data['codmodel'])) : '';
107 $p_chassisnumber = isset($data['chassisnumber']) ?
108 strtoupper(trim($data['chassisnumber'])) : '';
109 $p_platenumber = isset($data['platenumber']) ?
110 strtoupper(trim($data['platenumber'])) : '';
111 $p_dateFrom = isset($data['dateFrom']) ? trim($data['dateFrom']) : date('Y-m-d');
112 $p_codpolo = isset($data['codpolo']) ? trim($data['codpolo']) : null;
113
114 $len = strlen($data['vin']);
115 if ($len != 8 && $len != 17 && empty($p_codmodel) && empty($p_chassisnumber)
116 && empty($p_platenumber)
117 ) {
118 throw new \Exception(\Util::txtAPI(
119 'Please enter a valid VIN/CHASSIS.', $tokenproperties)
120 );
121 }
122
123 $chassis = ($len == 8) ? strtoupper($data['vin']) : '';
124 $vin = ($len == 17) ? strtoupper($data['vin']) : '';
125
126 $maindealer = \DealerBase::findMainDealer ($p_coddealer, $p_codmarket);
127 $codmaindealer = $maindealer[0];
128 if (empty($codmaindealer)) {
129 return \Util::ApiProblemResponse('findMainDealer', 'Invalid user HQ: ' . $p_coddealer);
130 }
131
132 // array for JSON response
133 $response = array();
134
135 /**
136 * Verifico che per il dealer in questione, debba chiamare Sap per lo stock utente oppure
137 * prenderlo dalle nostre tabelle.
138 */
139 $flagShipDealer = \FlagShipDealer::getSapConnectionRFC($p_codmarket, $p_coddealer);
140 if (empty($vin) && !empty($flagShipDealer) && $flagShipDealer[0]["DEALERTYPE"] == 'FC') { // es.: 0075250.D001
141
142 $pieces = explode(" ", $p_dateFrom);
143 $dataconsegna = null; //empty($p_codmodel) && empty($p_platenumber) ? $pieces[0] : null;
144
145 require_once (APPL_PATH . 'COMMON/classes/AgendaConsegna/controller/AgendaConsegnaController.php');
146
147 $codsincom = $p_coddealer;
148 $modello = $p_codmodel;
149 $targa = $p_platenumber;
150 $tboutput = null;
151 $telaio = $p_chassisnumber;
152 $sap_agenda = new \AgendaConsegnaController($p_codmarket, $codsincom, $dataconsegna,
153 $codpolo, $modello, $targa, $tboutput, $telaio);
154
155 $deliveries = $sap_agenda->getAgendaConsegnaArrayValue();
156
157 // looping through all results
158 // Events node
159 foreach($deliveries as $row) {
160 $fullname = trim ($row['Cognome'] . ' ' . $row['Nome']);
161 $vin = $row['Vin'];
162 $chassis = $row['Telaio'];
163 $plate = $row['Targa'];
164 $codmodel = $row['Modello'];
165 $codbrand = $row['Marca'];
166 $optstring = $row['Opt'];
167 $codupholstery = $row['ColoreInt'];
168 $phone = $row['Telefono'];
169 $email = $row['Mail'];
170 $codversion = $row['Versione'];
171 $codserie = $row['Serie'];
172 $codspecialserie = '000';
173 $codexternalcolor = $row['ColoreEst'];
174
175 $stockData = \StockBase::findByChassisModel($chassis, $p_codmarket, $codbrand,
176 $codmodel
177 );
178 if (!empty($stockData)) {
179 $vehicleInformation = \VehicleTransfer::findStockVeicleInformations(
180 $stockData[0]['CODORDER']
181 );
182 $vehicleInformation[0]['mvsdescription'] =
183 $stockData[0]['CODMODEL'] . '.' . $stockData[0]['CODVERSION'] . '.'
184 . $stockData[0]['CODSERIE'] . ' '
185 . $vehicleInformation[0]['VEHICLEDESCRIPTION'];
186 $optDesc = $this->getOptionalsDescription(
187 array($stockData[0]['CODORDER']), $p_codlanguage
188 );
189 $vehicleInformation[0]['optionaldesc'] = $optDesc[$stockData[0]['CODORDER']];
190 $vehicleInformation[0]['fullname'] = $fullname;
191 $vehicleInformation[0]['telephone'] = $phone;
192 $vehicleInformation[0]['email'] = $email;
193
194 $response[] = $vehicleInformation[0];
195 }
196 else {
197 // Ricerca su LDR_ANAGRAFICA_TELAI / SRV_VEHICLE.
198 $vehicle = Event\EventMapper::getVehicleInfos($p_codmarket, $p_coddealer,
199 $p_codlanguage, $vin, $plate, $chassis, $codmodel, $codbrand, $codversion,
200 $codserie, $codspecialserie, $codexternalcolor, $codupholstery
201 );
202
203 $vehicleInformation = array();
204
205 $vehicleInformation[0]['chassisnumber'] = $chassis;
206 $vehicleInformation[0]['codbrand'] = $codbrand;
207 $vehicleInformation[0]['codmodel'] = $codmodel;
208 $vehicleInformation[0]['codversion'] = $codversion;
209 $vehicleInformation[0]['codserie'] = $codserie;
210 $vehicleInformation[0]['codspecialserie'] = $codspecialserie;
211 $vehicleInformation[0]['codmarket'] = $p_codmarket;
212 $vehicleInformation[0]['optlist'] = $optstring;
213 $vehicleInformation[0]['coddealer'] = $p_coddealer;
214
215 $vehicleInformation[0]['fullname'] = $fullname;
216 $vehicleInformation[0]['telephone'] = $phone;
217 $vehicleInformation[0]['email'] = $email;
218
219 $vehicleInformation[0]['mvscode'] = $codmodel . $codversion . $codserie
220 . $codspecialserie;
221
222 $vehicleInformation[0]['codexternalcolor'] = $codexternalcolor;
223 $vehicleInformation[0]['externalcolordescription'] =
224 $vehicle['externalcolorname'];
225 $vehicleInformation[0]['codupholstery'] = $codupholstery;
226 $vehicleInformation[0]['upholsterydescription'] = $vehicle['upholsteryname'];
227
228 $commVehicle = new \CommercialVehicle();
229 $vehicleInformation[0]['mvsdescription'] = $commVehicle->getCompleteName(
230 $p_codmarket, $codbrand, $codmodel, $codversion, $codserie, $codspecialserie,
231 $p_codlanguage
232 );
233
234 // split a string after every 3 characters
235 $output = str_split($optstring, 3);
236
237 // prendo le descrizioni degli OPT.
238 $vehicleInformation[0]['optionaldesc'] = array();
239 $optlist2 = array();
240 $optVehicle = new \OptionalVehicle;
241
242 // looping through all results
243 // Opts node
244 $i=0;
245 foreach($output as $opt) {
246 //$r = self::getOptDescr($tmpArr, $tokenproperties, $opt);
247 $optionalArray = $optVehicle->findByPrimaryKeyLanguage(
248 $p_codmarket, $codbrand, $codmodel, $codversion, $codserie,
249 $codspecialserie, $opt, $p_codlanguage
250 );
251 /*
252 if ($optionalArray[0]['AVAILABILITY'] != 'O')
253 continue;
254 */
255 $entry = array(
256 'codopt' => $opt,
257 'description' => $optionalArray[0]['NOMBRE']
258 );
259 $vehicleInformation[0]['optionaldesc'][] = $entry;
260 $optlist2[$i] = $opt;
261 $i++;
262 }
263 $optstring = implode(", ", $optlist2);
264 $vehicleInformation[0]['optlist'] = $optstring;
265
266 $response[] = $vehicleInformation[0];
267 }
268 }
269
270 return new StockDealerCollection($response);
271 }
272
273 // 1. Ricerca su LDR_ANAGRAFICA_TELAI
274 $vehicles = \VinDrivenModel::findvehicledatabyparams (
275 $vin,
276 $p_codmarket,
277 $p_codlanguage,
278 empty($p_chassisnumber) ? $chassis : $p_chassisnumber,
279 $p_codmodel, //$model,
280 $p_platenumber //$plate
281 );
282
283 $dealerFound = true;
284 // looping through all results
285 // Vehicles node
286 if (!empty($vehicles)) {
287 $dealerFound = false;
288
289 foreach($vehicles as $row) {
290 $stockData = \StockBase::findByChassisModel($row['CHASSIS'], $p_codmarket, $row['CODBRAND'], $row['CODMODEL']);
291 if (!$stockData)
292 continue;
293
294 // filtro per dealer.
295 if (empty($flagShipDealer) || $flagShipDealer[0]["DEALERTYPE"] != 'FC') {
296 $maindealer = \DealerBase::findMainDealer ($stockData[0]['CODDEALER'], $p_codmarket);
297 if ($codmaindealer != $maindealer[0])
298 continue;
299 }
300
301 $dealerFound = true;
302
303 if (!empty($stockData) && !empty($stockData[0]['CODORDER'])) {
304 $codorder = $stockData[0]['CODORDER'];
305
306 // 1. check duplicates
307 $res = \DeliveryAgendaBase::findbyprimarykey($codorder);
308 if (!empty($res)) {
309 $evts = $res[0];
310 $codcontact = $evts['CODCONTACT'];
311 $contactData = \Contact::findContactDetails($codcontact, $p_coddealer, $p_codlanguage);
312
313 $timezone = \DateUtils::getTimezone($p_codmarket);
314
315 $row['CODCONTACT'] = $codcontact;
316 $row['CONTACTNAME'] = $contactData[0]['CONTACTNAME'];
317 $row['FIRSTNAME'] = $contactData[0]['FIRSTNAME'];
318 $row['DATE_DELIVERY'] = \DateUtils::fromUTC2Timezone($evts['DATE_DELIVERY_START'], $timezone);
319 $row['STATUS_EVENT'] = $evts['STATUS'];
320 $row['PHONE'] = $contactData[0]['TELEPHONE'];
321 $row['EMAIL'] = $contactData[0]['EMAIL'];
322 }
323
324 $vehicleInformation = \VehicleTransfer::findStockVeicleInformations($codorder);
325 if (empty($vehicleInformation)) {
326 $vehicleInformation = \Util::array_change_key_case_recursive( $row );
327 $vehicleInformation[0]['codorder'] = $codorder;
328 $vehicleInformation[0]['chassisnumber'] = $row['CHASSIS'];
329 $vehicleInformation[0]['codbrand'] = $row['CODBRAND'];
330 $vehicleInformation[0]['codmodel'] = $row['CODMODEL'];
331 $vehicleInformation[0]['codmarket'] = $p_codmarket;
332 $vehicleInformation[0]['codversion'] = $stockData[0]['CODVERSION'];
333 $vehicleInformation[0]['codserie'] = $stockData[0]['CODSERIE'];
334 $vehicleInformation[0]['codspecialserie'] = $stockData[0]['CODSPECIALSERIE'];
335 $vehicleInformation[0]['mvscode'] = $row['CODMVS'];
336 $vehicleInformation[0]['codexternalcolor'] = $row['CODEXTERNALCOLOR'];
337 $vehicleInformation[0]['codupholstery'] = $stockData[0]['CODUPHOLSTERY'];
338 $vehicleInformation[0]['codorderstatus'] = $stockData[0]['CODORDERSTATUS'];
339 $vehicleInformation[0]['price'] = $stockData[0]['PRICE'];
340 }
341
342 $vehicleInformation[0]['mvsdescription'] = $stockData[0]['CODMODEL'].'.'.$stockData[0]['CODVERSION'].'.'.$stockData[0]['CODSERIE'].' '.$vehicleInformation[0]['VEHICLEDESCRIPTION'];
343 $optDesc = $this->getOptionalsDescription(array($codorder), $p_codlanguage);
344 $vehicleInformation[0]['optionaldesc'] = $optDesc[$codorder];
345
346 $vehicleInformation[0]['CODCONTACT'] = $row['CODCONTACT'];
347 $vehicleInformation[0]['DATE_DELIVERY'] = $row['DATE_DELIVERY'];
348 $vehicleInformation[0]['STATUS_EVENT'] = $row['STATUS_EVENT'];
349 }
350 else {
351 $plate='';
352 $vin='';
353 $agendaStockSap = \DeliveryAgendaBase::findDeliveryAgendaStockSap($row['CHASSIS'], $p_codmarket, $p_coddealer, $row['CODBRAND'], $row['CODMODEL'],
354 $stockData[0]['CODVERSION'], $stockData[0]['CODSERIE'], $plate, $vin, $row['CODEXTERNALCOLOR'], $stockData[0]['CODUPHOLSTERY']);
355
356 if (!$agendaStockSap)
357 continue;
358
359 /*
360 $agendaStockSap = \DeliveryAgenda::findDeliveryAgendaStockSap('07398026', '1000', '0064260', '83', '191',
361 'B5R', '1', 'FA098JF', 'ZAR94000007398026', '289', '198');
362 */
363 if (!empty($agendaStockSap)) {
364 $agendaStockSap = \Util::array_change_key_case_recursive( $agendaStockSap );
365 $vehicleInformation = array();
366 $vehicleInformation[0] = $agendaStockSap[0];
367 }
368 }
369
370 $vehicleInformation[0]['codcommercialmodel'] = $row['CODCOMMERCIALMODEL'];
371 $vehicleInformation[0]['codcommercialversion'] = $row['CODCOMMERCIALVERSION'];
372
373 $vehicleInformation[0]['fullname'] = trim($row['CONTACTNAME'] .' '. $row['FIRSTNAME']);
374 $vehicleInformation[0]['telephone'] = $row['PHONE'];
375 $vehicleInformation[0]['email'] = $row['EMAIL'];
376
377 $opts = array();
378 $tmpPacks = array();
379 // Ricerca optserie.
380 $optserie = self::getOptSerie($opts, $vehicleInformation[0], $tokenproperties['CODLANGUAGE'], $codwheel, explode(', ', $vehicleInformation[0]['OPTLIST']), $tmpPacks);
381 $vehicleInformation[0]['codwheel'] = $codwheel;
382 $vehicleInformation[0]['optserie'] = $optserie;
383 $vehicleInformation[0]['packs'] = !empty($tmpPacks) ? implode(',', $tmpPacks) : '';
384 $vehicleInformation[0]['packopt'] = !empty($tmpPacks) ? self::getPackOpt($tmpPacks, $vehicle['CODMARKET'], $row['CODBRAND'], $row['CODMODEL'], $stockData[0]['CODVERSION'], $stockData[0]['CODSERIE'], $stockData[0]['CODSPECIALSERIE'], $tokenproperties['CODLANGUAGE']) : '';
385
386 $response[] = $vehicleInformation[0];
387 }
388 }
389
390
391 // 2. Ricerca su SRV_VEHICLE
392 if (empty($response) && !empty($vin)) {
393 $sigi = new \SIGILoaderVehicle($p_codmarket, NULL, NULL, $vin);
394
395 $contactVehicle = \ContactVehicle::findByVin($vin, $p_codlanguage, $p_coddealer, $p_codmarket);
396 if (empty($contactVehicle)) {
397 //throw new \Exception(\Util::txtAPI('Vehicle not found', $tokenproperties));
398 //return \Util::ApiProblemResponse('findByVin', 'Vehicle not found');
399 return new StockDealerCollection($response);
400 }
401
402 $result = array();
403 $vehicleData = \SRVVehicleBase::findByKeyNomap($p_codlanguage, $contactVehicle[0]['CODVEHICLE']);
404 if (empty($vehicleData)) {
405 //throw new \Exception(\Util::txtAPI('Vehicle not found', $tokenproperties));
406 //return \Util::ApiProblemResponse('findByKeyNomap', 'Vehicle not found');
407 return new StockDealerCollection($response);
408 }
409
410 $stockData = \StockBase::findByChassisModel($vehicleData[0]['CHASSIS'], $p_codmarket, $vehicleData[0]['CODBRAND'], $vehicleData[0]['CODMODEL']);
411 if (empty($stockData)) {
412 //throw new \Exception(\Util::txtAPI('Vehicle not in stock', $tokenproperties));
413 //return \Util::ApiProblemResponse('findByChassisModel', 'Vehicle not in stock');
414 return new StockDealerCollection($response);
415 }
416
417 // filtro per dealer.
418 $maindealer = \DealerBase::findMainDealer ($stockData[0]['CODDEALER'], $p_codmarket);
419 if ($codmaindealer == $maindealer[0])
420 {
421 $vehicleInformation = \VehicleTransfer::findStockVeicleInformations($stockData[0]['CODORDER']);
422 $vehicleInformation[0]['mvsdescription'] = $stockData[0]['CODMODEL'].'.'.$stockData[0]['CODVERSION'].'.'.$stockData[0]['CODSERIE'].' '.$vehicleInformation[0]['VEHICLEDESCRIPTION'];
423 $optDesc = $this->getOptionalsDescription(array($stockData[0]['CODORDER']), $tokenproperties['CODLANGUAGE']);
424 $vehicleInformation[0]['optionaldesc'] = $optDesc[$stockData[0]['CODORDER']];
425 $vehicleInformation[0]['codcommercialmodel'] = $vehicleData[0]['CODCOMMERCIALMODEL'];
426 $vehicleInformation[0]['codcommercialversion'] = $vehicleData[0]['CODCOMMERCIALVERSION'];
427
428 $opts = array();
429 $tmpPacks = array();
430 // Ricerca optserie.
431 $optserie = self::getOptSerie($opts, $vehicleInformation[0], $tokenproperties['CODLANGUAGE'], $codwheel, explode(', ', $vehicleInformation[0]['OPTLIST']), $tmpPacks);
432 $vehicleInformation[0]['codwheel'] = $codwheel;
433 $vehicleInformation[0]['optserie'] = $optserie;
434 $vehicleInformation[0]['packs'] = !empty($tmpPacks) ? implode(',', $tmpPacks) : '';
435 $vehicleInformation[0]['packopt'] = !empty($tmpPacks) ? self::getPackOpt($tmpPacks, $p_codmarket, $vehicleData[0]['CODBRAND'], $vehicleData[0]['CODMODEL'], $stockData[0]['CODVERSION'], $stockData[0]['CODSERIE'], $stockData[0]['CODSPECIALSERIE'], $tokenproperties['CODLANGUAGE']) : '';
436
437 $response = $vehicleInformation;
438 }
439 }
440
441 // codorder belongs to another dealer
442 /*
443 if ($dealerFound == false) {
444 return \Util::ApiProblemResponse('getStockDataByVin', \Util::txtAPI('Codorder belongs to another dealer', $tokenproperties));
445 }
446 */
447
448 $isLCVModel = $this->isLCVfromMVSS($tokenproperties['CODMARKET'],
449 $response[0]['CODBRAND'], $response[0]['CODMODEL'],
450 $response[0]['CODVERSION'], $response[0]['CODSERIE'],
451 $response[0]['CODSPECIALSERIE'], $tokenproperties['CODLANGUAGE']
452 );
453 if ($isLCVModel) {
454 $response[0]['CODBRAND'] = '77';
455 }
456
457 //return new StockDealerCollection($response);
458
459 return $response;
460 }
461
462 private function getOptionalsDescription($arrayCodOrder, $codLanguage) {
463 $optionalArray = \StockOptional::getOptionalsByGroupOfCodOrders($arrayCodOrder, $codLanguage);
464 $arrayOptionalDescription = array();
465 foreach ($optionalArray as $key => $value) {
466 $arrayOptionalDescription[$value['CODORDER']][] = array(
467 "codopt" => $value['CODOPTIONAL'],
468 "description" => $value['OPTIONALDESCR']
469 //"availability" => $value['OPTIONALAVAILABILITY']
470 );
471 }
472 return $arrayOptionalDescription;
473 }
474
475 /**
476 * Ritorno tutti gli opt per un certo MVS (solo quelli con availability S).
477 * Per riferimento ritorniamo l'array degli opt (opts) in modo
478 * da evitare chiamate duplicate per lo stesso MVS e il codwheel. [B36249]
479 *
480 * @param array $opts
481 * @param array $vehicle
482 * @param string $codLanguage
483 * @param string $codwheel
484 * @param array $optList
485 * @return string
486 */
487 private function getOptSerie(&$opts, $vehicle, $codLanguage, &$codwheel, $optList, &$tmpPacks)
488 {
489 $codcolor = $vehicle['CODEXTERNALCOLOR'];
490 $codupholstery = $vehicle['CODUPHOLSTERY'];
491 $codbillcategory = 20;
492 $environment = 'O';
493 $simulationDate = '';
494 $codwheel = '000';
495
496 $key = $vehicle['CODMARKET'] . '_' . $vehicle['CODBRAND'] . '_' . $vehicle['CODMODEL']
497 . '_' . $vehicle['CODVERSION'] . '_' . $vehicle['CODSERIE'] . '_'
498 . $vehicle['CODSPECIALSERIE'];
499
500 if (!isset($opts[$key])) {
501 $optsList = $this->getOptionals(
502 $vehicle['CODMARKET'], $vehicle['CODBRAND'], $vehicle['CODMODEL'],
503 $vehicle['CODVERSION'], $vehicle['CODSERIE'], $vehicle['CODSPECIALSERIE'],
504 $codcolor, $codupholstery, $codLanguage, $codbillcategory, $environment,
505 $simulationDate
506 );
507
508 if (empty($optsList))
509 return '';
510
511 $opts[$key] = $optsList;
512 } else {
513 $optsList = $opts[$key];
514 }
515
516 $tmpOpts = array();
517 foreach ($optsList as $key => $value) {
518 if ($value['CODOPTIONALCATEGORY'] == 8 && !empty($optList) && in_array(
519 $value['CODOPTIONAL'], $optList)
520 ) {
521 $codwheel = $value['CODOPTIONAL'];
522 }
523
524 // x packs.
525 if ($value['ISPACK'] == 1 && ($value['AVAILABILITY'] == 'S' || (!empty($optList)
526 && in_array($value['CODOPTIONAL'], $optList)))
527 ) {
528 $tmpPacks[] = $value['CODOPTIONAL'];
529 }
530
531 if ($value['AVAILABILITY'] != 'S')
532 continue;
533
534 $tmpOpts[] = $value['CODOPTIONAL'];
535 }
536
537 if ($codwheel == '000') {
538 $codwheel = self::getCodWheel($vehicle, $codLanguage, $simulationDate);
539 }
540
541 /*
542 // ciclo x packs.
543 foreach ($optsList as $key => $value) {
544 if ($value['ISPACK'] == 1 && ($value['AVAILABILITY'] == 'S' || (!empty($optList) && in_array($value['CODOPTIONAL'], $optList))) ) {
545 $tmpPacks[] = $value['CODOPTIONAL'];
546 }
547 }
548 */
549
550 return implode(',', $tmpOpts);
551 }
552
553 public function getOptionals ($codmarket, $codbrand, $codmodel, $codversion, $codserie,
554 $codspecialserie, $codcolor, $codupholstery, $codlanguage, $codbillcategory, $environment,
555 $simulationDate = null, $p_availability = 'O'
556 ) {
557 // instanzio il Controller per gli Optionals del percorso offerta di link
558 $OptsController = & \OptionalDataController::singleton('OfferOptionalDataController');
559 // Ottengo la lista degli opt per MVS- Environment - Colori
560 $optsList = $OptsController->getValidOptionalList(
561 $codmarket, $codbrand, $codmodel, $codversion, $codserie, $codspecialserie, $codcolor,
562 $codupholstery, $codlanguage, $codbillcategory, $environment, $simulationDate, $p_availability
563 );
564 return $optsList;
565 }
566
567 /**
568 * Metodo per determinare se un veicolo appartiene a brand LCV da mercato, brand, MVSS e lingua.
569 *
570 * @param string $codMarket
571 * @param string $codBrand
572 * @param string $codModel
573 * @param string $codVersion
574 * @param string $codSerie
575 * @param string $codSpecialSerie
576 * @param string $codLanguage
577 */
578 private function isLCVfromMVSS($codMarket, $codBrand, $codModel, $codVersion, $codSerie,
579 $codSpecialSerie, $codLanguage
580 ) {
581 $codBillCategory = '20'; // per APP sembra sia irrilevante
582 $commVehicle = \CommercialVehicle::findByPrimaryKey($codMarket, $codBrand, $codModel,
583 $codVersion, $codSerie, $codSpecialSerie, $codLanguage, $codBillCategory
584 );
585
586 if ($commVehicle[0]['CODBRAND'] === '00' && $commVehicle[0]['CODVEHICLETYPE'] === '02') {
587 return true;
588 }
589
590 return false;
591 }
592
593 /** getCommModel
594 *
595 * @param String $codMarket
596 * @param String $codBrand
597 * @param String $codCommercialModel
598 * @param String $codLanguage
599 * @throws \Exception
600 * @return Array
601 */
602 public function getCommModel($codMarket, $codBrand, $codCommercialModel, $codLanguage)
603 {
604 $res = \CommercialModel::findByPrimaryKey($codMarket, $codBrand, $codCommercialModel, $codLanguage);
605 if (!$res) {
606 //throw new \Exception("CommercialModel not found!");
607 return null;
608 }
609 $commmodels = \Util::array_change_key_case_recursive( $res );
610
611 return (count($commmodels) > 0 ? $commmodels[0] : null);
612 }
613
614 /*
615 * $tokenProperties, $companyName, $firstname, $lastname, $telephone,
616 * $customerEmail, $flagPrivacy,
617 * $codmarket, $codmaindealer, $codlanguage
618 */
619 public static function storeContact(
620 $tokenProperties,
621 $companyName,
622 $firstname,
623 $lastname,
624 $codcontact = '',
625 $flagPrivacy = '',
626 $phone = '',
627 $cellular = '',
628 $jobphone = '',
629 $homephone = '',
630 $email = '',
631 $address = '',
632 $addressnumber = '',
633 $zipcode = '',
634 $codcity = '',
635 $desc_city = '',
636 $codnation = '',
637 $codgender = '',
638 $codtitle = '',
639 $birthdate = '',
640 $urlwebsite = '',
641 $p_codContactSource = '',
642 $initials = '',
643 $codCustomerSource = '',
644 $notes = '',
645 $modelofinterest = ''
646 ) {
647 $loginname = $tokenProperties['LOGINNAME'];
648 $codmarket = $tokenProperties['CODMARKET'];
649 $codmaindealer = $tokenProperties['CODDEALER'];
650 $codlanguage = $tokenProperties['CODLANGUAGE'];
651 $foreignlocality = null;
652
653 // $_SESSION['SS_CODMAINDEALER'] ora necessario per id privacy contesto
654 $_SESSION["SS_CODMARKET"] = $codmarket;
655 $_SESSION['SS_CODMAINDEALER'] = $codmaindealer;
656
657 $privacyEngineController = new \PrivacyEngineController();
658 $privacyLength = strlen($flagPrivacy);
659
660 // PRIVACY_UE_ENABLE
661 $PRIVACY_UE_ENABLE = \Util::isMultichannelPrivacy($codmarket);
662
663 // Verify on multichannel privacy availability for used market
664 if (!$PRIVACY_UE_ENABLE) {
665 // old privacy
666 if ($privacyLength > 1) {
667 /*return new BaseException(
668 BaseException::BAD_PARAMETERS, 'Market without multichannel Privacy'
669 );*/
670
671 var_dump(BAD_PARAMETERS, 'Market without multichannel Privacy');
672 }
673 } else {
674 // multichannel privacy
675 $flagPrivacy = strtoupper($flagPrivacy);
676 // test on multichannel privacy for correct format
677 $testPrivacyValue = $privacyLength < 1 || preg_match('/[G]*[F]*/', $flagPrivacy) === 0;
678 if ($testPrivacyValue) {
679 /*
680 return new BaseException(BaseException::BAD_PARAMETERS, 'Wrong Privacy value');
681 */
682
683 //var_dump(BAD_PARAMETERS, 'Wrong Privacy value');
684 }
685
686 // take new privacy and mantain compatibility with old privacy system
687 $pcyArray = $flagPrivacy;
688 $flagPrivacy = '1';
689 }
690
691 // foreignlocality
692 if (( empty($codcity) || $codcity == 0 ) && !empty($desc_city))
693 {
694 if (empty($codnation))
695 {
696 // usa il codnation dell'utente, almeno questo e' necessario
697 $codnation = \Nazioni::getNationForUser($codmarket, $codmaindealer);
698 }
699 // saves the city name...
700 $foreignlocality = $codnation . ',,ET,' . $desc_city;
701
702 $codnation = '';
703 }
704
705 /** Contact Company section */
706 if ($companyName) {
707 $existsCompany = \Contact::findByCompanyName(
708 $companyName, $phone, $codmarket, $codmaindealer, $codlanguage
709 );
710
711 if (empty($codcontact)) {
712 $codcontact = (is_array($existsCompany[0]) && !empty($existsCompany[0])) ?
713 $existsCompany[0]['CODCONTACT'] : null;
714 }
715
716 if (!empty($existsCompany[0])) {
717 // special case: cellular can be resetted if APP pass no value for it...
718 $cellular = empty($cellular)
719 && $p_codContactSource !== \Contact::getCodContactSource('iLinkWelcome') ?
720 $existsCompany[0]['CELULAR'] : $cellular;
721 $address = !empty($address) ? $address : $existsCompany[0]['ADDRESS1'];
722 $addressnumber = !empty($addressnumber) ?
723 $addressnumber : $existsCompany[0]['ADDRESSNUMBER'];
724 $zipcode = !empty($zipcode) ? $zipcode : $existsCompany[0]['CAP'];
725 $codcity = !empty($codcity) ? $codcity : $existsCompany[0]['CODCITY'];
726 $codnation = !empty($codnation) ? $codnation : $existsCompany[0]['CODNATION'];
727 $foreignlocality = !empty($foreignlocality) ?
728 $foreignlocality : $existsCompany[0]['CODNATION'];
729 $codCustomerSource = !empty($codCustomerSource) ?
730 $codCustomerSource : $existsCompany[0]['CODCUSTOMERSOURCE'];
731 $notes = !empty($notes) ? $notes : $existsCompany[0]['NOTES'];
732
733 // required for modelofinterest (it is only here), or it may lose already setted value
734 $companyContactData = self::getContactByCod(
735 $tokenProperties, $existsCompany[0]['CODCONTACT']
736 );
737 $modelofinterest = !empty($modelofinterest) ?
738 $modelofinterest : $companyContactData['modelofinterest'];
739 }
740
741 // $contact is always the company or the person (the main contact)
742 $contact = new \GenericContact($loginname, $codmarket, $codmaindealer, $codlanguage,
743 array(
744 'codcontact' => $codcontact,
745 'codcontacttype' => 'C',
746 'firstname' => $firstname,
747 'lastname' => $lastname,
748 'companyname' => $companyName,
749 'telephone' => $phone,
750 'celular' => $cellular,
751 'dataprotection' => $flagPrivacy,
752 'email' => $email,
753 'address1' => $address,
754 'addressnumber' => $addressnumber,
755 'cap' => $zipcode,
756 'city' => $desc_city,
757 'codcity' => $codcity,
758 'codnation' => $codnation,
759 'foreignlocality' => $foreignlocality,
760 'codContactSource' => $p_codContactSource,
761 'codcustomersource' => $codCustomerSource,
762 'info' => $notes, // mapped as info in StoreContact
763 'modelofinterest' => $modelofinterest
764 )
765 );
766
767 // we search for the main reference...
768 /* $reference = (is_array($existsCompany[0]) && !empty($existsCompany[0])) ?
769 $existsCompany[0]['PERSONA_CONTACTO'] : null; */
770
771 /** we search for at least a reference */
772 $references = \Contact::getContactReferences($codcontact);
773 if (empty($references)) {
774 /** create new reference contact */
775 $reference = new \ReferenceContact($loginname, $codmarket, $codmaindealer,
776 $codlanguage,
777 array(
778 'firstnameReference' => $firstname,
779 'lastnameReference' => $lastname,
780 'telephoneReference' => $phone,
781 'celularReference' => $cellular,
782 'dataprotectionReference' => $flagPrivacy,
783 'emailReference' => $email,
784 'address1Reference' => $address,
785 'addressnumberReference' => $addressnumber,
786 'capReference' => $zipcode,
787 'cityReference' => $desc_city,
788 'codcityReference' => $codcity,
789 'codnationReference' => $codnation,
790 'foreignlocalityReference' => $foreignlocality,
791 'codcustomersourceReference' => $codCustomerSource,
792 'modelofinterestReference' => $modelofinterest
793 ), $contact
794 );
795 } else {
796 /** search reference contact */
797 $exists = \Contact::findByPersonName($firstname, $lastname, $phone, $codmarket,
798 $codmaindealer, $codlanguage
799 );
800 if ($exists[0]['CODCONTACTTYPE'] == 'R') {
801 $codReference = (is_array($exists[0]) && !empty($exists[0])) ?
802 $exists[0]['CODCONTACT'] : null;
803 }
804
805 /** update (or create if not exist) reference contact */
806 $reference = new \ReferenceContact($loginname, $codmarket, $codmaindealer,
807 $codlanguage,
808 array(
809 'codcontactReference' => $codReference,
810 'firstnameReference' => $firstname,
811 'lastnameReference' => $lastname,
812 'telephoneReference' => $phone,
813 'celularReference' => $cellular,
814 'dataprotectionReference' => $flagPrivacy,
815 'emailReference' => $email,
816 'address1Reference' => $address,
817 'addressnumberReference' => $addressnumber,
818 'capReference' => $zipcode,
819 'cityReference' => $desc_city,
820 'codcityReference' => $codcity,
821 'codnationReference' => $codnation,
822 'foreignlocalityReference' => $foreignlocality,
823 'codcustomersourceReference' => $codCustomerSource,
824 'modelofinterestReference' => $modelofinterest
825 ), $contact
826 );
827 }
828 $codcontact = $contact->store();
829
830 if ($reference->isValid()) {
831 $codreferencecontact = $reference->store();
832 }
833 /** Contact Person section */
834 } else {
835 $codcontact = !$codcontact ? self::getCodContact($tokenProperties, $firstname,
836 $lastname, $phone, $cellular) : $codcontact;
837 $codtitle = !$codtitle ? self::getTitleByCodGender($tokenProperties,
838 $codgender) : $codtitle;
839
840 $modifiedData = array(
841 'codcontacttype' => 'P',
842 'firstname' => $firstname,
843 'lastname' => $lastname,
844 'telephone' => $phone,
845 'celular' => $cellular,
846 'job_phone' => $jobphone,
847 'home_phone' => $homephone,
848 'dataprotection' => $flagPrivacy,
849 'email' => $email,
850 'address1' => $address,
851 'addressnumber' => $addressnumber,
852 'cap' => $zipcode,
853 'city' => $desc_city,
854 'codcity' => $codcity,
855 'codnation' => $codnation,
856 'foreignlocality' => $foreignlocality,
857 'codtitle' => $codtitle,
858 'codgender' => $codgender,
859 'birthdate' => $birthdate,
860 'url_website' => $urlwebsite,
861 'codContactSource' => $p_codContactSource,
862 'initials' => $initials,
863 'info' => $notes,
864 'modelofinterest' => $modelofinterest,
865 'codcustomersource' => $codCustomerSource
866 );
867
868 if (!empty($codcontact)) {
869 // contact exist, add API data to contact data
870 $contactData = self::getContactByCod($tokenProperties, $codcontact);
871
872 if ($p_codContactSource == \Contact::getCodContactSource('iLinkWelcome')) {
873 $modifiedData['email'] = empty($email) ? '[NULL]' : $email;
874 $modifiedData['telephone'] = empty($phone) ? '[NULL]' : $phone;
875 $modifiedData['celular'] = empty($cellular) ? '[NULL]' : $cellular;
876 $modifiedData['address1'] = empty($address) ? '[NULL]' : $address;
877 $modifiedData['addressnumber'] = empty($addressnumber) ? '[NULL]' : $addressnumber;
878 $modifiedData['cap'] = empty($zipcode) ? '[NULL]' : $zipcode;
879 $modifiedData['city'] = empty($desc_city) ? '[NULL]' : $desc_city;
880 }
881
882 // mapping of fields with different key for store contact
883 $modifiedData['celular'] = $cellular ? $cellular : $contactData['celular'];
884 $modifiedData['job_phone'] = $jobphone ? $jobphone : $contactData['telephone_work'];
885 $modifiedData['home_phone'] = $homephone ?
886 $homephone : $contactData['telephone_home'];
887 $modifiedData['birthdate'] = $birthdate ? $birthdate : $contactData['birthdate'];
888 $modifiedData['url_website'] = $urlwebsite ? $urlwebsite : $contactData['web'];
889
890 $modifiedContact = array_filter(array_merge($contactData, $modifiedData));
891 // special case: cellular can be resetted if APP pass no value for it...
892 $modifiedContact['celular'] = empty($cellular)
893 && $p_codContactSource !== \Contact::getCodContactSource('iLinkWelcome') ?
894 $contactData['celular'] : $cellular;
895 $modifiedContact['foreignlocality'] = $foreignlocality;
896 $modifiedContact['codcity'] = !empty($codcity) ? $codcity : $contactData['codcity'];
897 $modifiedContact['dataprotection'] = strlen($flagPrivacy) > 0 ?
898 $flagPrivacy : $contactData['dataprotection'];
899 // mapping origin for contact
900 $modifiedContact['codcustomersource'] = !empty($codCustomerSource) ?
901 $codCustomerSource : $contactData['codcustomersource'];
902 // notes is mapped as info in StoreContact
903 $modifiedContact['info'] = !empty($notes) ? $notes : $contactData['notes'];
904
905 $modifiedContact['modelofinterest'] = !empty($modelofinterest) ?
906 $modelofinterest : $contactData['modelofinterest'];
907
908 // * b34087 ***
909 // 1. Se l'API non manda ne' codcity ne' foreign locality...
910 if (( empty($codcity) || $codcity == 0 ) && empty($foreignlocality)) {
911 $modifiedContact['codnation'] = $contactData['codnation'];
912 $modifiedContact['codregion'] = $contactData['codregion'];
913 $modifiedContact['coddepartment'] = $contactData['coddepartment'];
914 }
915 // 2. se l'API manda DescrCity salvo foreignLocality...
916 else if (empty($codcity) && !empty($foreignlocality)) {
917 $modifiedContact['codcity'] = null;
918 $modifiedContact['codnation'] = null;
919 $modifiedContact['codregion'] = null;
920 $modifiedContact['coddepartment'] = null;
921 //$modifiedContact['foreignlocality'] = null;
922
923 $codnation = \Nazioni::getNationForUser($codmarket, $codmaindealer);
924
925 $city = self::getCity($codnation, $desc_city, $codlanguage);
926 if (!empty($city)) {
927 $modifiedContact['foreignlocality'] = null;
928 $modifiedContact['codcity'] = $city['codcity'];
929 $modifiedContact['codnation'] = empty($codnation) ?
930 $city['codnation'] : $codnation;
931 $modifiedContact['codregion'] = $city['codregion'];
932 $modifiedContact['coddepartment'] = $city['coddepartment'];
933
934 $modifiedContact['city'] = $city['descr_city'];
935 $modifiedContact['cityname'] = $city['descr_city'];
936 $modifiedContact['cap'] = $city['zipcode'];
937 }
938 }
939 // 3. se l'API manda codCity devo eliminare foreignLocality...
940 else if (!empty($codcity)) {
941 $modifiedContact['codnation'] =
942 !empty($contactData['codnation']) ? $contactData['codnation'] : $codnation;
943 $modifiedContact['codregion'] = $contactData['codregion'];
944 $modifiedContact['coddepartment'] = $contactData['coddepartment'];
945 $modifiedContact['foreignlocality'] = null;
946 }
947 } else {
948 // contact not exist, use only API data
949 $modifiedContact = $modifiedData;
950 }
951
952 if ($codmarket === '3112') {
953 $modifiedContact['cap'] = $zipcode;
954 }
955
956 $modifiedContact['codcontact'] = $codcontact;
957
958 $contact = new \GenericContact($loginname, $codmarket, $codmaindealer, $codlanguage,
959 $modifiedContact
960 );
961
962 $contact->store();
963 }
964
965 if ($contact->isValid() && $pcyArray) {
966 $contesto = null;
967 if (in_array($p_codContactSource, array(
968 \Contact::getCodContactSource('iLinkConf'),
969 \Contact::getCodContactSource('iLinkTradeIn')
970 ))
971 ) {
972 $contesto = 'offer';
973 } else if (in_array($p_codContactSource, array(
974 \Contact::getCodContactSource('iLinkWelcome'),
975 \Contact::getCodContactSource('iLinkDelivery')
976 ))
977 ) {
978 $contesto = 'contact';
979 }
980
981 $idContesto = $privacyEngineController->getIdPrivacyContesto($contesto);
982 // convert input in 10 channel privacy
983 $pcyArray = \Util::convertContactPrivacyString($pcyArray, $idContesto, $codmarket);
984
985 // store new privacy in contact
986 $ris = $privacyEngineController->savePrivacy(
987 $idContesto, $contact->getCodContact(), $pcyArray
988 );
989
990 if ($codreferencecontact) {
991 // store privacy for company reference contact
992 $privacyEngineController->savePrivacy(
993 $idContesto, $reference->getCodContact(), $pcyArray
994 );
995 }
996 }
997
998 //Response...
999 $contactData = self::getContactByCod($tokenProperties, $contact->getCodContact());
1000 $referenceData = $reference ?
1001 self::getReferentByCod($tokenProperties, $reference->getCodContact()) : null;
1002
1003 $result = array(
1004 'codcontact' => $contact->getCodContact(),
1005 'codcontacttype' => $contactData["codcontacttype"],
1006 'firstname' => $contactData["firstname"],
1007 'lastname' => $contactData["contactname"],
1008 'codreferencecontact' => $reference ? $reference->getCodContact() : null,
1009 'firstnameReference' => $reference ? $referenceData["firstname"] : null,
1010 'lastnameReference' => $reference ? $referenceData["contactname"] : null
1011 );
1012
1013 return $result;
1014 }
1015
1016 /** getContactByCod
1017 *
1018 * @param Array $obj
1019 * @param string $codcontact
1020 * @return Array
1021 */
1022 public static function getContactByCod($obj, $codcontact, $ex = true)
1023 {
1024 $contacts = \Contact::findContactDetails($codcontact, $obj['CODMARKET'], $obj['CODLANGUAGE']); // contiene i duplicati...
1025 if ( empty( $contacts ) ) {
1026 if ($ex)
1027 throw new \Exception("Contact not found!");
1028 else
1029 return null;
1030 }
1031
1032 $details = \Util::array_change_key_case_recursive( $contacts );
1033
1034 return $details[0];
1035 }
1036
1037 /** buildTemplate
1038 *
1039 * @param array $tokenProperties
1040 * @param array $params
1041 * @return string
1042 */
1043 public function buildTemplate( $tokenProperties, $params )
1044 {
1045 $tpl = APPL_PATH . 'COMMON/TplHTML/Delivery/default.php';
1046 $tpl2 = APPL_PATH . 'COMMON/TplHTML/Delivery/tpl_with_backg.php';
1047 if (!file_exists($tpl) || !file_exists($tpl2)) {
1048 throw new \Exception("Template not Found!");
1049 }
1050
1051 $codmarket = $tokenProperties['CODMARKET'];
1052 $p_codDealer = $tokenProperties['CODDEALER'];
1053 $p_codLanguage = $tokenProperties['CODLANGUAGE'];
1054 $codmaindealer = $tokenProperties['CODDEALER'];
1055 $codcontact = $params['codcontact'];
1056 $codbrand = $params['codbrand'];
1057 //$brandName = $params['brandName'];
1058 $codcommercialmodel = $params['codcommercialmodel'];
1059 $modelName = $params['modelName'];
1060 $fullname = $params['fullname'];
1061 $codgender = $params['codgender'];
1062
1063 $brandData = \Brand::findbyprimarykey($codbrand);
1064 $brandName = $brandData[0]['BRANDNAME'];
1065 $mondoFiatApp = \iLinkApp::geAppMondoFCAbybrand($codbrand);
1066 $mondoFiatAppData = array();
1067 foreach ($mondoFiatApp as $key => $value) {
1068 $mondoFiatAppData[$value['OS']] = $value;
1069 }
1070
1071 $_ENV['codbrand'] = $codbrand;
1072 $_ENV['bgcolor'] = '#f0ebe7';
1073 $_ENV['header_height'] = 120;
1074 //$_ENV['footer_height'] = 40;
1075
1076 if ($codbrand == '00') // FIAT
1077 {
1078 // nuovo template FIAT.
1079 $_ENV['bgcolor'] = '#FFFFFF';
1080 $_ENV['header_height'] = 210;
1081 $_ENV['footer_height'] = 180;
1082 $_ENV['header'] = 'header_00_white.jpg';
1083 $_ENV['footer'] = 'footer_00_white.jpg';
1084 }
1085 else if ($codbrand == '57') // JEEP
1086 {
1087 /*
1088 $_ENV['bgcolor'] = '#f0ebe7';
1089 $_ENV['header_height'] = 120;
1090 $_ENV['footer_height'] = 40;
1091 */
1092
1093 $_ENV['bgcolor'] = '#000';
1094 $_ENV['color'] = '#FFF';
1095 $_ENV['label_color'] = '#DDAF11';
1096 $_ENV['bar_color'] = '#FFF';
1097 $_ENV['bar_bgcolor'] = '#333';
1098 //$_ENV['header_height'] = 100;
1099 $_ENV['footer_height'] = 40;
1100 $_ENV['header'] = 'header_57_black.jpg';
1101 $_ENV['footer'] = 'footer_57_black.jpg';
1102 }
1103 else if ($codbrand == '66') // ABARTH
1104 {
1105 $_ENV['bgcolor'] = '#011422';
1106 $_ENV['color'] = '#FFFFFF';
1107 }
1108 else if ($codbrand == '70') // LANCIA
1109 {
1110 $_ENV['bgcolor'] = '#E4E0DF';
1111 $_ENV['color'] = '#0D323B';
1112 }
1113 else if ($codbrand == '83') // ALFAROMEO
1114 {
1115 $_ENV['bgcolor'] = '#FFFFFF';
1116 $_ENV['color'] = '#000000';
1117 $_ENV['header_height'] = 80;
1118 $_ENV['footer_height'] = 140;
1119 }
1120
1121 $color = $_ENV['color'];
1122
1123 $path_img = DIR_PHOTO_DELIVERY_MNG;
1124 $path_store = "http://linkentry-euro.fiat.com/attachments/images/";
1125
1126 // gestione 'codgender'
1127 if ($codgender == 'M') {
1128 $titlePerson = addslashes(\Util::txtAPI("Sig.", $tokenProperties));
1129 $dearPerson = addslashes(\Util::txtAPI("Caro", $tokenProperties));
1130 }
1131 else if ($codgender == 'F') {
1132 $titlePerson = addslashes(\Util::txtAPI("Sig.ra", $tokenProperties));
1133 $dearPerson = addslashes(\Util::txtAPI("Cara", $tokenProperties));
1134 } else {
1135 $titlePerson = '';
1136 $dearPerson = addslashes(\Util::txtAPI("Caro/a", $tokenProperties));
1137 }
1138
1139 $oggetto = trim(\Util::txtAPI("Congratulations for your", $tokenProperties) ." ". $brandName ." - ". $modelName);
1140
1141 $dealerLocation = \DealerLocationBase::findDealerMainLocation($codmarket, $p_codDealer);
1142
1143 $_ENV['subject'] = $oggetto;
1144 $params['dearPerson'] = $dearPerson;
1145 $params['fullname'] = $fullname;
1146 $params['modelName'] = $modelName;
1147 $params['photo_src1'] = !empty($params['photo']) ? $path_img . $codmarket."_".$codmaindealer."_".$codcontact."_".date("dmY").".jpg" : null;
1148 $params['photo_src2'] = !empty($params['photo2']) ? $path_img . $codmarket."_".$codmaindealer."_".$codcontact."_".date("dmY")."_2.jpg" : null;
1149 $params['photo_src1'] = 'http://linkentry-euro.fiat.com/attachments/images/ipadImages/androidStore.png';
1150 $params['photo_src2'] = 'http://linkentry-euro.fiat.com/attachments/images/ipadImages/androidStore.png';
1151 $params['path_store'] = $path_store;
1152 $params['brandName'] = $brandName;
1153 $_ENV['params'] = $params;
1154 $_ENV['mondoFiatAppData'] = $mondoFiatAppData;
1155 $_ENV['tokenProperties'] = $tokenProperties;
1156 $_ENV['dealerLocation'] = $dealerLocation;
1157
1158 /*
1159 // Testare e agganciare il nuovo template 'store'.
1160 $tplTMP = APPL_PATH . 'COMMON/TplHTML/Delivery/store.php';
1161 $_ENV['body'] = \Util::get_include_contents($tplTMP);
1162 $bodyMailHtml = \Util::get_include_contents($tpl);
1163 //var_dump($bodyMailHtml); die;
1164 return $bodyMailHtml;
1165 */
1166
1167 $bodyMailHtml = "<p style='font-family:Helvetica,Arial,sans-serif;font-size:15px;color: $color;'>". $dearPerson . " <b>" . $fullname . "</b>, <br/><br/>" .
1168 \Util::txtAPI('Congratulazioni per la sua nuova', $tokenProperties)." ".$modelName.'</p>';
1169
1170 if ($params['photo']) {
1171 $bodyMailHtml .= '<br/>';
1172 //$img = "<img src='" . $params['photo_src1'] . "' data-default='placeholder' data-max-width='600' width='512'>";
1173 $img = "<img src='" . $path_img . $codmarket."_".$codmaindealer."_".$codcontact."_".date("dmY").".jpg"."' data-default='placeholder' data-max-width='600' width='512'>";
1174
1175 $div = '<div class="movableContent">
1176 <table width="550" border="0" cellspacing="0" cellpadding="0" >
1177 <tr>
1178 <td align="center">
1179 <div class="contentEditableContainer contentImageEditable">
1180 <div class="contentEditable" >';
1181 $div .= $img;
1182 $div .= '</div>
1183 </div>
1184 </td>
1185 </tr>';
1186
1187 if ($params['photo2']) {
1188 //$img2 = "<img src='" . $params['photo_src2'] . "' data-default='placeholder' data-max-width='600' width='512'>";
1189 $img2 = "<img src='" . $path_img . $codmarket."_".$codmaindealer."_".$codcontact."_".date("dmY")."_2.jpg"."' data-default='placeholder' data-max-width='600' width='512'>";
1190 $div .= '<tr height="10"></tr>';
1191 $div .= '<tr>
1192 <td align="center">
1193 <div class="contentEditableContainer contentImageEditable">
1194 <div class="contentEditable" >';
1195 $div .= $img2;
1196 $div .= '</div>
1197 </div>
1198 </td>
1199 </tr>';
1200 }
1201
1202 $div .= '</table>
1203 </div>';
1204
1205 $bodyMailHtml .= $div;
1206 }
1207 $bodyMailHtml .= "<br/><p style='font-family:Helvetica,Arial,sans-serif;font-size:15px;color: $color;'>" . \Util::txtAPI("Vogliamo farle notare i controlli fatti alla sua vettura poco prima della consegna:", $tokenProperties)."</p><br/>";
1208 $bodyMailHtml .= "<ul style='font-family:Helvetica,Arial,sans-serif;font-size:15px;margin-left:25px;color: $color;'>";
1209
1210 if (!empty($params['arrayDescriptionItem'])) {
1211 foreach ($params['arrayDescriptionItem'] as $key => $value) {
1212 //$bodyMailHtml .= "<li>". \Util::clean($value) ."</li>";
1213 $bodyMailHtml .= "<li>" . trim($value) . "</li>";
1214 }
1215 }
1216 $bodyMailHtml .="</ul><br/>";
1217
1218 $bodyMailHtml .= "<p style='font-family:Helvetica,Arial,sans-serif;font-size:15px;color: $color;'>" . \Util::txtAPI("Per agevolare il suo ingresso all’interno del mondo $brandName, la invitiamo a scoprire le App dedicate a Lei che può scaricare sullo store",$tokenProperties).'</p>';
1219 $bodyMailHtml .='<table>';
1220 $bodyMailHtml .='<tr>';
1221 $bodyMailHtml .="<td style='font-family:Helvetica,Arial,sans-serif;font-size:15px;color: $color;'>".$mondoFiatAppData['iOS']['DESCRIPTION'] . \Util::txtAPI(" per iPhone", $tokenProperties).'</td>';
1222 $bodyMailHtml .="<td style='font-family:Helvetica,Arial,sans-serif;font-size:15px;color: $color;'>".$mondoFiatAppData['Android']['DESCRIPTION'] . \Util::txtAPI(" per Android", $tokenProperties).'</td>';
1223 $bodyMailHtml .='</tr><tr height="16px"></tr><tr>';
1224
1225 $bodyMailHtml .='<td align="center"><a href="'.$mondoFiatAppData['iOS']['URL'].'"><img src="' . $path_store . 'ipadImages/appleStore.png" style:"display:inline;"></a></td>';
1226 $bodyMailHtml .='<td align="center"><a href="'.$mondoFiatAppData['Android']['URL'].'"><img src="' . $path_store . 'ipadImages/androidStore.png" style:"display:inline;"></a></td></tr>';
1227
1228 $bodyMailHtml .= "</table><br/><p style='font-family:Helvetica,Arial,sans-serif;font-size:15px; color: $color;'>";
1229
1230 $bodyMailHtml .= "<p style='font-family:Helvetica,Arial,sans-serif;font-size:15px;color: $color;'>" . \Util::txtAPI("Scopra anche tutti i servizi e le offerte dedicate a Lei da parte di Mopar cliccando qui sotto:<br>", $tokenProperties);
1231 $bodyMailHtml .= "<a href='http://www.mopar.eu/' style='font-family:Helvetica,Arial,sans-serif;font-size:15px; color: $color;'>http://www.mopar.eu</a><br/><br/>";
1232
1233 $bodyMailHtml .= \Util::txtAPI("Sia le App che il sito Mopar sono stati progettati intorno a Lei per fare in modo di rendere unica la sua esperienza all’interno del mondo $brandName. Se ha qualche domanda in merito contatti pure il suo contatto personale o il nostro service department.",$tokenProperties);
1234 $bodyMailHtml .= '<br/><br/>' . \Util::txtAPI("Grazie per la sua attenzione e buon viaggio sulla sua nuova $brandName.", $tokenProperties);
1235 $bodyMailHtml .= '</p><br/><br/>';
1236
1237
1238 $dealerLocation = \DealerLocationBase::findDealerMainLocation($codmarket, $p_codDealer);
1239 if ($dealerLocation) {
1240 $bodyMailHtml .= "<p style='font-family:Helvetica,Arial,sans-serif;font-size:15px;color: $color;'>". $dealerLocation[0]['NAME'].'</p><br/>';
1241 }
1242
1243 $_ENV['body'] = $bodyMailHtml;
1244
1245 $path = "http://linkentry-euro.fiat.com/attachments/images/brands/delivery/";
1246 $header = $path . 'header_' . $codbrand . '.jpg';
1247 $body_bg = $path . 'body_' . $codbrand . '.jpg';
1248
1249 if (\Util::file_url_exists($body_bg)) {
1250 $bodyMailHtml = \Util::get_include_contents($tpl2);
1251 } else {
1252 $bodyMailHtml = \Util::get_include_contents($tpl);
1253 }
1254
1255 return $bodyMailHtml;
1256 }
1257
1258 /** deliveryPhotoPcyEmail
1259 *
1260 * @param string $data
1261 * @param object $tokenProperties
1262 * @throws \Exception
1263 */
1264 public function deliveryPhotoPcyEmail($data = ArrayObject, $tokenProperties)
1265 {
1266 $coddealer = $tokenProperties['CODDEALER'];
1267 $codlanguage = $tokenProperties['CODLANGUAGE'];
1268 $codmarket = $tokenProperties['CODMARKET'];
1269 $flagPrivacy = $data['privacy'];
1270 $loginname = $tokenProperties['LOGINNAME'];
1271 $email = $data['email'];
1272 $sendmail = isset($data['sendmail']) ? trim($data['sendmail']) : '';
1273 $p_pcy_email = isset($data['pcy_email']) ? intval($data['pcy_email']) : 0;
1274 $p_pcy_social = isset($data['pcy_social']) ? intval($data['pcy_social']) : 0;
1275 $p_output = isset($data['output']) ? $data['output'] : null;
1276 $p_pcy_type = 2; // 2 (DISCLOSURE)
1277
1278 // controllo flag.
1279 if ($p_pcy_type != 1 && $p_pcy_type != 2) {
1280 $p_pcy_type = 1;
1281 }
1282 if ($p_pcy_email != 0 && $p_pcy_email != 1) {
1283 $p_pcy_email = 0;
1284 }
1285 if ($p_pcy_social != 0 && $p_pcy_social != 1) {
1286 $p_pcy_social = 0;
1287 }
1288
1289 $_ENV['PCY_TYPE'] = $p_pcy_type .' '. $p_pcy_email .' '. $p_pcy_social;
1290
1291 $dealerData = \DealerBase::findByPrimaryKeyDealer($codmarket, $coddealer);
1292
1293 # EMAIL
1294 $res = \iLinkApp::getAllDeliveryPcy($codmarket, $codlanguage, self::$EMAIL_BODY);
1295 $html = (!empty($res) && !empty($res[0]['PLAIN'])) ? $res[0]['PLAIN'] : null;
1296 $html .= '<br/><br/><hr/>';
1297
1298 // pcy_type == 2 (DISCLOSURE)
1299 if ($_ENV['PCY_TYPE'] == '2 1 1') {
1300 $res = \iLinkApp::getAllDeliveryPcy($codmarket, $codlanguage, 7);
1301 $plain = (!empty($res) && !empty($res[0]['PLAIN'])) ? $res[0]['PLAIN'] : null;
1302 $_ENV['DISCLOSURE_EMAIL_AND_SOCIAL'] = $plain;
1303
1304 //$html .= $_ENV['DISCLOSURE_EMAIL_AND_SOCIAL'];
1305 $html .= '<font size="2">' . $_ENV['DISCLOSURE_EMAIL_AND_SOCIAL'] . '</font>';
1306 }
1307 else if ($_ENV['PCY_TYPE'] == '2 1 0') {
1308 $res = \iLinkApp::getAllDeliveryPcy($codmarket, $codlanguage, 5);
1309 $plain = (!empty($res) && !empty($res[0]['PLAIN'])) ? $res[0]['PLAIN'] : null;
1310 $_ENV['DISCLOSURE_EMAIL'] = $plain;
1311
1312 $html .= '<font size="2">' . $_ENV['DISCLOSURE_EMAIL'] . '</font>';
1313 }
1314 else if ($_ENV['PCY_TYPE'] == '2 0 1') {
1315 $res = \iLinkApp::getAllDeliveryPcy($codmarket, $codlanguage, 6);
1316 $plain = (!empty($res) && !empty($res[0]['PLAIN'])) ? $res[0]['PLAIN'] : null;
1317 $_ENV['DISCLOSURE_SOCIAL'] = $plain;
1318
1319 //$html .= $_ENV['DISCLOSURE_SOCIAL'];
1320 $html .= '<font size="2">' . $_ENV['DISCLOSURE_SOCIAL'] . '</font>';
1321 }
1322
1323 $html = str_replace('[DEALER_NAME]', $dealerData[0]['NAME'], $html);
1324 $html = str_replace('[DEALER_MAIL]', $dealerData[0]['MAIL'], $html);
1325 //$html = str_replace('[DEALER_ADDRESS]', '', $html);
1326 //$html = str_replace('[TODAY]', date("d/m/Y"), $html);
1327 //$html = str_replace('[DISCLOSURE_PCY]', $dealerData[0]['MAIL'], $html);
1328
1329 $_ENV['EMAIL'] = $html;
1330 //var_dump($plain); die;
1331
1332 //$tpl = APPL_PATH . ($p_pcy_type == 2 ? 'COMMON/TplHTML/Pcy/pcy_disclosure.php' : 'COMMON/TplHTML/Pcy/pcy_statement.php');
1333 $tpl = APPL_PATH . 'COMMON/TplHTML/Pcy/pcy_email.php';
1334
1335 //$bodyMailHtml = self::buildDeliveryPhotoPcyTemplate($tokenProperties, $params);
1336 $bodyMailHtml = \Util::get_include_contents($tpl);
1337 if ($p_output == 'html') {
1338 //echo $bodyMailHtml; die;
1339 }
1340
1341 /**
1342 * Invio la mail solamente se lo status = 1 -> delivery completata
1343 */
1344 $mail = false;
1345 // invio email
1346 try {
1347 $to = array(
1348 'mail' => $email, 'name' => $firstname. " " . $lastname
1349 );
1350 $from = array(
1351 'mail' => 'marketing_team@fiat.com'
1352 //'name' => $userData[0]['FIRSTNAME']. " " . $userData[0]['LASTNAME']
1353 );
1354
1355 $oggetto = \Util::txtAPI("iLinkDeliveryPcyPhotoSubject ", $tokenProperties);
1356 // inserimento del processo per l'invio dell'email nella jobqueue di zend-server
1357 $ris = \Util::mailInJobQueue(
1358 $tokenProperties, __CLASS__, __FUNCTION__, $oggetto, $bodyMailHtml, $to, $from
1359 );
1360
1361 if (is_int($ris)) {
1362 $mail = true;
1363 }
1364 } catch (\Exception $e) {
1365 $mail = false;
1366 }
1367
1368 return $mail;
1369 }
1370
1371 public function setEntry ($o) { $this->entry = $o; }
1372 public function setModule ($o) { $this->module = $o; }
1373
1374 /**
1375 * I setter per passare al controller i dati
1376 */
1377 public function setCodMarket ($codMarket) { $this->codMarket = $codMarket; }
1378 public function setCodMainDealer ($codMainDealer) { $this->codMainDealer = $codMainDealer; }
1379 public function setCodLanguage ($codLanguage) { $this->codLanguage = $codLanguage; }
1380 public function setLoginName ($loginname) { $this->loginname = $loginname; }
1381
1382 public function setCodContact ($codcontact) { $this->codcontact = $codcontact; }
1383 public function setCodContactType ($codcontacttype) { $this->codcontacttype = $codcontacttype; }
1384 public function setLastname ($lastname) { $this->lastname = $lastname; }
1385 public function setFirstname ($firstname) { $this->firstname = $firstname; }
1386 public function setVin ($vin) { $this->vin = $vin; }
1387 public function setDatedelivery ($datedelivery) { $this->datedelivery = $datedelivery; }
1388 public function setDatedelivery_to ($datedelivery_to) { $this->datedelivery_to = $datedelivery_to; }
1389 //public function setVehiclename ($vehiclename) { $this->vehiclename = $vehiclename; }
1390 public function setVehicledescr ($vehicledescr) { $this->vehicledescr = $vehicledescr; }
1391 public function setUsergid ($usergid) { $this->usergid = $usergid; }
1392 public function setCodorder ($codorder) { $this->codorder = $codorder; }
1393 public function setPlate ($plate) { $this->plate = $plate; }
1394 public function setDateFrom ($dateFrom) { $this->dateFrom = $dateFrom; }
1395 public function setDateTo ($dateTo) { $this->dateTo = $dateTo; }
1396 public function setCodDeliveryAgenda ($coddeliveryagenda) { $this->coddeliveryagenda = $coddeliveryagenda; }
1397 public function setFullname ($fullname) { $this->fullname = $fullname; }
1398 public function setEvent_id ($event_id) { $this->event_id = $event_id; }
1399 public function setStatus ($status) { $this->status = $status; }
1400 public function setGids ($gids) { $this->gids = $gids; }
1401 public function setNote ($note) { $this->note = $note; }
1402
1403 public function setModel ($model) { $this->model = $model; }
1404 public function setChassis ($chassis) { $this->chassis = $chassis; }
1405}
1406?>