Guest User

Untitled

a guest
Dec 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 124.15 KB | None | 0 0
  1. <?php
  2. namespace iLinkQuotation\V2\Rest\Quotation;
  3.  
  4. use Application\Controller\BaseException;
  5. require_once APPL_PATH . 'oracle.showroom.loc/class/Offer.class.php';
  6. require_once APPL_PATH . 'oracle.showroom.loc/class/Dealer.class.php';
  7. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_sesion_showroom.php';
  8. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_extrabase.php';
  9. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_promociones.php';
  10. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_parametric_tax_category.php';
  11. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_parametric_tax.php';
  12. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_extrabase.php';
  13. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_extrabase_excluyente.php';
  14. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_extra_operacion.php';
  15. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_tipo_promocion.php';
  16. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_promocion_opcional.php';
  17. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_descuento_concesionario.php';
  18. require_once APPL_PATH . 'oracle.showroom.loc/offer/model/Accessors.class.php';
  19. require_once APPL_PATH . 'oracle.showroom.loc/offer/model/Eproduct.class.php';
  20. require_once APPL_PATH . 'oracle.showroom.loc/offer/model/ValidateOffer.class.php';
  21. require_once APPL_PATH . 'oracle.showroom.loc/offer/used_vehicle/model/UsedVehicle1000.class.php';
  22. require_once APPL_PATH . 'oracle.showroom.loc/offer/controller/OfferController.class.php';
  23. require_once APPL_PATH . 'oracle.showroom.loc/libs/base.lib.php';
  24. require_once APPL_PATH . 'oracle.showroom.loc/crm_wii/model/crm_wii.class.php';
  25. require_once APPL_PATH . 'COMMON/classes/OfferBase.class.php';
  26. require_once APPL_PATH . 'COMMON/classes/Nazioni.class.php';
  27. require_once APPL_PATH . 'COMMON/classes/Util.class.php';
  28. require_once APPL_PATH . 'oracle.showroom.loc/class/Offer.class.php';
  29. require_once APPL_PATH . 'COMMON/classes/MappingParameters.class.php';
  30. require_once APPL_PATH . 'COMMON/classes/class_opcional.php';
  31. require_once APPL_PATH . 'COMMON/classes/class_impuesto_version.php';
  32. require_once APPL_PATH . 'COMMON/classes/IPTBase.class.php';
  33. require_once APPL_PATH . 'COMMON/classes/MarketOfferBreakPoints.class.php';
  34. require_once APPL_PATH . 'COMMON/classes/CommercialVehicle.class.php';
  35. require_once APPL_PATH . 'COMMON/pricing/PriceItemCollection.class.php';
  36. require_once APPL_PATH . 'COMMON/pricing/PriceItemCollectionTaxOverrider.class.php';
  37. require_once APPL_PATH . 'COMMON/pricing/PriceEngine.class.php';
  38. require_once APPL_PATH . 'COMMON/classes/TRK_SpecialSales.class.php';
  39. require_once APPL_PATH . 'COMMON/classes/TRK_Stock.class.php';
  40. require_once APPL_PATH . 'COMMON/classes/OcfModel.class.php';
  41. require_once APPL_PATH . 'COMMON/classes/ILinkOffer/IlinkPromotion.class.php'; //B42226 - Applicazone IVA (corretta) alle promozioni
  42. require_once APPL_PATH . 'COMMON/classes/CarConfB2C_Loader.class.php';
  43.  
  44.  
  45. // CONTROLLER
  46. require_once APPL_PATH . 'oracle.showroom.loc/offer/controller/OfferSummaryController.class.php';
  47. require_once APPL_PATH . 'oracle.showroom.loc/offer/controller/OfferPrintedControllerUE.class.php';
  48.  
  49. // PRINT
  50. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_color_language.php';
  51. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_color_tapiceria.php';
  52. require_once APPL_PATH . 'oracle.showroom.loc/clases/class_tipo_combustible_language.php';
  53.  
  54. use COMMON\classes\TRK_SpecialSales;
  55.  
  56. /**
  57. *
  58. * @see http://linkentry.fiat.com/mobile/ilcc/sampleJson/
  59. */
  60. class QuotationMapper
  61. {
  62.  
  63. /**
  64. * oggetto Offer
  65. *
  66. * @var \Offer
  67. */
  68. private $offer;
  69.  
  70. /**
  71. * variabile che contiene gli attributi di sessione
  72. *
  73. * @var array
  74. */
  75. private $tokenProperties;
  76.  
  77. private $timezone;
  78.  
  79. private $codCurrency;
  80.  
  81. private $localeid;
  82.  
  83. /**
  84. * costruttore not so lazy...
  85. * inizializza il token che contiene le variabili di sessione
  86. *
  87. * @param unknown $tokenProperties
  88. */
  89. public function __construct($tokenProperties)
  90. {
  91. $this->tokenProperties = $tokenProperties;
  92. // recupero gli attributi del mercato da utilizzare a livello locale
  93. $marketObj = \Market::findByPrimaryKey($this->tokenProperties['CODMARKET']);
  94. $this->timezone = $marketObj[0]['TIMEZONE_REGION'];
  95. $this->codCurrency = $marketObj[0]['CODCURRENCY'];
  96. $this->localeid = $marketObj[0]['LOCALE_ID'];
  97.  
  98. }
  99.  
  100. public function getOffer()
  101. {
  102. return $this->offer;
  103. }
  104.  
  105. public function setOffer($offer)
  106. {
  107. $this->offer = $offer;
  108. }
  109.  
  110. /**
  111. * Metodo usato per retrocompatibilità con le vecchie classi di esales.
  112. *
  113. * @param string $codoffer
  114. */
  115. public function initSession($codoffer)
  116. {
  117. $_SESSION['SS_USER_PRIVILEGES'][] = 'VN'; // / da vedere
  118. $_SESSION['SS_CODMARKET'] = $this->tokenProperties['CODMARKET'];
  119. $_SERVER['CODMARKET'] = $this->tokenProperties['CODMARKET'];
  120. $GLOBALS['SS_CODMARKET'] = $this->tokenProperties['CODMARKET'];
  121. $_SESSION['SS_CODLANGUAGE'] = $this->tokenProperties['CODLANGUAGE'];
  122. $_SESSION['SS_FLAGSHIP_DEALER'] = ''; // dipende dal coddelaer!!
  123. $_SESSION['SS_VIP_FLAGSHIP'] = ''; // da ricavare
  124. $_SESSION['OFFERPATH'] = '';
  125. $_SESSION['SS_USERNAME'] = $this->tokenProperties['LOGINNAME']; // @TODO
  126. $_SESSION['SS_WORKING_VEHTYPE'] = '01'; // @TODO
  127. $_SESSION['STOCKOFFER'] = '0'; // @TODO
  128. $_SESSION['DOC_ALLESTIMENTO'] = '';
  129. $_SESSION['ALL_DISC'] = '';
  130. $_SESSION['SS_OFFER_VIEW_TYPE'] = 1; // tax + detax
  131. $_SESSION['SS_APPLTYPE'] = 'ESALES';
  132. $_SESSION['SS_LOGINNAME'] = $this->tokenProperties['LOGINNAME'];
  133. $_SESSION['SS_CODMAINDEALER'] = self::getCodMainDealer($this->tokenProperties['CODMARKET'],
  134. $this->tokenProperties['CODDEALER']);
  135. $_SESSION['SS_CODDEALER'] = $this->tokenProperties['CODDEALER'];
  136. //$_SESSION['SS_CUSTOMER_TYPE'] = 'P'; // P or C
  137. $_SESSION['SS_ISAPI'] = 1; // necessario per le traduzioni.
  138.  
  139. // il barbatrucco che fa funzionare le classi esales è qui,
  140. // dove si mette il codice offerta in sessione :P
  141. $_SESSION['CK_SESION'] = $codoffer;
  142. $_SESSION['CK_MONEY_SYMBOL'] = '€'; // @TODO
  143.  
  144. $codNation = \Nazioni::getNationForUser($this->tokenProperties['CODMARKET'],
  145. $this->tokenProperties['CODDEALER']);
  146.  
  147. if($_SERVER['CODMARKET'] == "3239") {
  148. $offerBase = new \OfferBase();
  149. $offerBaseData = $offerBase->findOfferByPrimaryKey($codoffer);
  150. $_SESSION['SS_CODBILLCATEGORY'] = $offerBaseData[0]['CODBILLCATEGORY'];
  151. } else {
  152. $_SESSION['SS_CODBILLCATEGORY'] = \Util::getCodBillCategory(
  153. $this->tokenProperties['CODMARKET'], $this->tokenProperties['CODDEALER'], $codNation,
  154. $this->tokenProperties['CODLANGUAGE']);
  155. }
  156. // $params['ROLECODE']
  157. // $params['UPSAPPLICATIONNAME']
  158.  
  159.  
  160. // INSTANTIATE OFFER DATA OBJECTS
  161. $offer = new \Offer();
  162.  
  163. // prendo le info sul modello data l'offerta.
  164. if ($offer->findByPrimaryKey($codoffer)) {
  165.  
  166. $this->setOffer($offer);
  167.  
  168. $commercialVehicle = \CommercialVehicle::findByPrimaryKey($offer->getCodMarket(),
  169. $offer->getCodBrand(), $offer->getCodModel(), $offer->getCodVersion(),
  170. $offer->getCodSerie(), $offer->getCodSpecialSerie(),
  171. $this->tokenProperties['CODLANGUAGE']);
  172. $_SESSION['SS_VEHICLE_TYPE'] = !empty($commercialVehicle) ? $commercialVehicle[0]['CODVEHICLETYPE'] : '01';
  173. $_SESSION ['SS_WORKING_VEHTYPE'] = $_SESSION['SS_VEHICLE_TYPE'];
  174. // il metodo OfferPathController::getCodoffer antepone il valore
  175. // presente nella $_REQUEST al valore di sessione
  176. $_REQUEST['codoffer'] = $codoffer;
  177. $_SESSION['CK_CLIENTE_SHOWROOM'] = $offer->getCodContact();
  178. $_SESSION['SS_CODBRAND'] = $offer->getCodBrand();
  179. $_SESSION['SS_CODMODEL'] = $offer->getCodModel();
  180. $_SESSION['SS_CODLOCATION'] = $offer->getCodDealerLocation();
  181. $_SESSION["SS_CODNATION"] = $offer->getCodNation();
  182. $_SESSION['CK_COUNTRY'] = $offer->getCodNation();
  183. $_SESSION['SS_CODDEALER'] = $offer->getCodDealer();
  184. $_SESSION['CK_CONCESIONARIO'] = $offer->getCodMarket() . '_' . $offer->getCodDealer() .
  185. '_' . $offer->getCodDealerLocation();
  186.  
  187. $_SESSION['SS_WORKING_CODMAINDEALER'] = $this->tokenProperties['CODDEALER'];
  188. $_SESSION['SS_WORKING_CODBRAND'] = $offer->getCodBrand();
  189. $_SESSION['SS_WORKING_CODDEALER'] = $offer->getCodDealer();
  190.  
  191. // check codnation
  192. if (empty($_SESSION["SS_CODNATION"])) {
  193. $dealer = \Dealer::findDealerByPk($offer->getCodMarket(), $offer->getCodDealer());
  194.  
  195. if (empty($dealer) || empty($dealer[0]['CODNATION'])) {
  196. return new BaseException(BaseException::BAD_PARAMETERS,
  197. 'codNation could not be empty!');
  198. }
  199.  
  200. $_SESSION["SS_CODNATION"] = $dealer[0]['CODNATION'];
  201. $_SESSION['CK_COUNTRY'] = $dealer[0]['CODNATION'];
  202. }
  203.  
  204. // Variabili necessarie per la stampa dell'offerta.
  205. // NetworkBrand sarebbe da spostare in >COMMON/classes
  206. require_once (APPL_PATH . 'welcome/classes/networkBrand.class.php');
  207.  
  208. $networkBrand = \NetworkBrand::findNetworkByCodDealer($_SESSION['SS_CODMARKET'],
  209. $_SESSION['SS_CODDEALER'], '');
  210.  
  211. // UserProfile
  212. // require_once(APPL_PATH . 'oracle.showroom.loc/class/UserProfile.class.php');
  213.  
  214. // $userProfile = new \UserProfile();
  215. // $roles = array();
  216. $roles = array(
  217. 'RGIT.LINK'
  218. );
  219. $userPrivileges = self::getPrivileges($_SESSION['SS_CODMARKET'], $roles);
  220.  
  221. // [DM] TASK 622 - Pricing rounding rules
  222. $roundingRules = \Market::getRoundingRules($_SESSION['SS_CODMARKET']);
  223.  
  224. $codnation = \Nazioni::getNationForUser($_SESSION['SS_CODMARKET'],
  225. $_SESSION['SS_CODMAINDEALER']);
  226.  
  227. $roleType = 'ALL';
  228. $userRole = 'RGIT.LINK';
  229.  
  230. $_SESSION['SS_CODNETWORKAREA'] = $networkBrand['CODNETWORKAREA'];
  231. $_SESSION['SS_CODNETWORKZONE'] = $networkBrand['CODNETWORKZONE'];
  232. $_SESSION['SS_CODNETWORKBRAND'] = '';
  233. $_SESSION['SS_DEALER_NETWORK_LEVEL'] = '1';
  234. // $_SESSION['SS_CODLINK'] = 20;
  235. // $_SESSION['SS_USER_PRIVILEGES'] = $userPrivileges;
  236. $_SESSION['SS_ROLETYPE'] = $roleType;
  237. $_SESSION['SS_CODROLE'] = $userRole;
  238. $_SESSION['SS_ROUNDINGRULES'] = $roundingRules;
  239. $_SESSION['CK_MONEY_SYMBOL'] = $this->codCurrency;
  240. $_SESSION['SS_MONEY_SYMBOL'] = $this->codCurrency;
  241.  
  242. // Gestione date offer.
  243. $_SESSION['SS_LOCALE_MONTHS'] = array(
  244. txt("Enero"),
  245. txt("Febrero"),
  246. txt("Marzo"),
  247. txt("Abril"),
  248. txt("Mayo"),
  249. txt("Junio"),
  250. txt("Julio"),
  251. txt("Agosto"),
  252. txt("Septiembre"),
  253. txt("Octubre"),
  254. txt("Noviembre"),
  255. txt("Diciembre")
  256. );
  257.  
  258. $_SESSION['SS_LOCALE_DAYS'] = array(
  259. txt('Lunes'),
  260. txt('Martes'),
  261. txt('Miercoles'),
  262. txt('Jueves'),
  263. txt('Viernes'),
  264. txt('Sabado'),
  265. txt('Domingo')
  266. );
  267.  
  268. $_SESSION['SS_LOCALE_ID'] = $this->localeid;
  269. $_SESSION['SS_LOCALE_FRAC_DIGITS'] = "2";
  270. $_SESSION['SS_LOCALE_THOUSANDS_SEP'] = ".";
  271. $_SESSION['SS_LOCALE_DECIMAL_POINT'] = ",";
  272. $_SESSION['SS_LOCALE_MON_THOUSANDS_SEP'] = ".";
  273. $_SESSION['SS_LOCALE_MON_DECIMAL_POINT'] = ",";
  274. $_SESSION['SS_LOCALE_DATEFORMAT']['short'] = str_replace('-', '/', explode(' ', \DateUtils::getDateFormat())[0]);
  275.  
  276. // info dealer.
  277. /*
  278. * $dealerData = \DealerBase::findByPrimaryKeyDealer($_SESSION['SS_CODMARKET'], $_SESSION['SS_CODDEALER']); if (!$dealerData) throw new \Exception("DealerData not found!");
  279. */
  280.  
  281. $userData = \ElinkUser::findUserbyPk($_SESSION['SS_CODMARKET'],
  282. $this->tokenProperties['LOGINNAME']);
  283. if (!$userData)
  284. throw new \Exception("UserData not found!");
  285.  
  286. $_SESSION['SS_USERNAME'] = $userData[0]['FIRSTNAME'] . ' ' . $userData[0]['LASTNAME'];
  287.  
  288. // da verificare.
  289. if ($_SESSION['SS_VEHICLE_TYPE'] == '01') {
  290. $_SERVER['CODLINK'] = self::getCodLink($this->tokenProperties['UPSAPPLICATIONNAME'],
  291. $_SESSION['SS_CODBRAND']);
  292. } else {
  293. $_SERVER['CODLINK'] = '9';
  294. }
  295. $_SESSION['SS_CODLINK'] = $_SERVER['CODLINK'];
  296. } else {
  297. throw new BaseException(BaseException::PROCESS_ERROR,
  298. "Quotation::init: Offer {$codoffer} not found!");
  299. }
  300. }
  301.  
  302. /**
  303. * ritorna un oggetto Quotation per chiave
  304. *
  305. * @param int $codoffer
  306. */
  307. public function getQuotation($codoffer)
  308. {
  309.  
  310. // inizializzazione delle variabili d'ambiente
  311. $this->initSession($codoffer);
  312.  
  313. // carichiamo l'OfferController che usiamo come DAO...
  314. $offerController = new \OfferController();
  315.  
  316. $offerController->viewType = 0;
  317. $offerController->changeViewType = 1;
  318. $offerController->codoffer = $codoffer;
  319.  
  320. // attualizziamo l'offerta
  321. $offerController->process(true);
  322.  
  323. // istanza della classe che rappresenta la quotazione
  324. // il costruttore invoca il metodo QuotationEntity::update()
  325. // che fa l'override del BaseEntity::update()
  326. $quotationEntity = new QuotationEntity($offerController, $this->timezone);
  327. $quotationEntity->offervalidity = $this->getOfferValidity($codoffer);
  328.  
  329. //echo '<pre>'; var_dump($offerController); exit();
  330.  
  331. /**
  332. * Dati del veicolo da percorso offerta
  333. */
  334. $configuration = array(
  335. 'brandConf' => '57',
  336. 'metadataModel' => '6094',
  337. 'modelDescription' => 'Renegade MY19',
  338. 'configDescription' => 'Renegade MY19 SPORT 1.0 GSE T3 120cv FWD',
  339. 'modelName' => 'Renegade MY19',
  340. 'footerPrivacy' => '',
  341. 'useExtdFilters' => 'True',
  342. 'showMvsList' => 'False',
  343. 'useLMFIPlus' => 'True',
  344. 'predictiveGrids' => 'True',
  345. 'groups' => 'ENGN|DRVE|GEAR|FUEL|EQPM|BODY|SEAT|WHEL|PACK',
  346. 'LMFIModel' => '',
  347. 'mvs' => '57609L204000',
  348. 'device' => 'D',
  349. 'co2' => '134',
  350. 'body' => '176$5CJ',
  351. 'whel' => 'WDJ',
  352. 'seat' => '009#-',
  353. 'eqpm' => '010',
  354. 'drve' => '1',
  355. 'engn' => '10',
  356. 'fuel' => '2',
  357. 'gear' => '43',
  358. 'pack' => '',
  359. 'opts' => '|009#-|011|023|025|026|112|132|198|264|392|416|4DK|4JA|505|511|5A0|5BH|176$5CJ|5DE|5J9|631|BGG|BNS|CGW|CJ2|JAY|JTM|MXU|RCG|RS9|RSW|UGA|WDJ',
  360. 'price' => '22400',
  361. 'priceNoVat' => '17581.97'
  362. );
  363.  
  364. $this->getQrCodeFromConf($configuration);
  365.  
  366. return $quotationEntity;
  367. }
  368.  
  369. /**
  370. * ritorna una collezione di oggetti Quotation
  371. *
  372. * @param string $date in formato Y-m-d
  373. */
  374. public function listQuotation($p_offerdateFrom, $p_offerdateTo)
  375. {
  376.  
  377. // $debug = $pippo;
  378. $p_codlanguage = $this->tokenProperties['CODLANGUAGE'];
  379. $p_loginname = $this->tokenProperties['LOGINNAME'];
  380.  
  381. $offs = \OfferBase::findAllByLoginname($p_loginname, $p_codlanguage, $p_offerdateFrom, $p_offerdateTo);
  382.  
  383. if (empty($offs)) {
  384. return new QuotationCollection();
  385. }
  386.  
  387. $collection = new QuotationCollection();
  388.  
  389. foreach ($offs as $item) {
  390.  
  391. //var_dump($item); die;
  392. $quotation = new QuotationEntity($item, $this->timezone);
  393.  
  394. $quotation->contactname = $item['FULLNAME'];
  395. $quotation->versionname = $item['VEHICLEDESCR'];
  396. $quotation->quantity = intval($item['QUANTITY']);
  397. $quotation->ocfnumber = $item['OCFNUMBER'];
  398. $quotation->is_multiple = $item['IS_BASKET'] == 'Y' ? 'Y' : 'N';
  399. // @TODO: $quotation->offervalidity = nel cursore manca OFFER.DAYVALIDITYPERIOD
  400.  
  401. $collection->add($quotation);
  402. }
  403.  
  404. return $collection;
  405. }
  406.  
  407. /**
  408. * Verifica la possibilità di utilizzare un'offerta.
  409. *
  410. * @see /offer/validate.php
  411. *
  412. * @param string $codoffer
  413. * @return QuotationCollection
  414. */
  415. public function validateQuotation($codoffer)
  416. {
  417. // MANDATORY
  418. $summary = \ValidateOffer::validateSummary($codoffer);
  419.  
  420. if ($_SESSION['SS_FLAGSHIP_DEALER']) {
  421. $hasStock = true;
  422. $stock = true;
  423. } else {
  424. $hasStock = \ValidateOffer::hasStock($codoffer);
  425. $stock = \ValidateOffer::validateStock($codoffer);
  426. }
  427.  
  428. $color_upholstery[] = 'V';
  429. $mvs[] = 'V';
  430. if (!$hasStock) {
  431. $mvs = \ValidateOffer::validateMVS($codoffer);
  432. $color_upholstery = \ValidateOffer::validateColorAndUpholstery($codoffer);
  433. }
  434. // OPTIONALS
  435. $hasOptionals = \ValidateOffer::hasOptionals($codoffer);
  436. $hasAccessories = \ValidateOffer::hasAccessories($codoffer);
  437. $hasUsed = \ValidateOffer::hasUsed($codoffer);
  438. $hasFinancing = \ValidateOffer::hasFinancing($codoffer);
  439.  
  440. // CONDITIONAL CHECKS
  441. $globally_valid_accessories = true;
  442. if ($hasAccessories) {
  443. $accessories = \ValidateOffer::validateAccessories($codoffer);
  444. $globally_valid_accessories = ($accessories[0] != 'B');
  445. }
  446.  
  447. $globally_valid_optionals = true;
  448. if ($hasOptionals) {
  449. if (!$_SESSION['SS_FLAGSHIP_DEALER'] && !$hasStock) {
  450. $optionals = \ValidateOffer::validateOptionals($codoffer);
  451. $globally_valid_optionals = ($optionals[0] != 'B');
  452. } else {
  453. $optionals = \ValidateOffer::answerProcessor('');
  454. }
  455. }
  456.  
  457. // TOTAL VALIDATION SUMMARY
  458. $globally_valid = false;
  459. // for Sudafrica the check are limitated
  460. if ($_SESSION['SS_CODMARKET'] == MARKET_ZA) {
  461. if ($mvs[0] != 'B' and $color_upholstery[0] != 'B' and $summary[0] != 'B' and
  462. $globally_valid_optionals) {
  463. $globally_valid = true;
  464. }
  465. } else {
  466. if ($mvs[0] != 'B' and $color_upholstery[0] != 'B' and $summary[0] != 'B' and $stock and
  467. $globally_valid_accessories and $globally_valid_optionals) {
  468. $globally_valid = true;
  469. }
  470. }
  471.  
  472. // 1. MVS
  473. $notes = '';
  474. if (isset($mvs[1])) {
  475. foreach ($mvs[1] as $msg) {
  476. $notes .= \Util::txtAPI("offer validate - $msg", $this->tokenProperties) . '\n';
  477. }
  478. }
  479.  
  480. $sections[] = array(
  481. 'name' => \Util::txtAPI('offer validate - mvs', $this->tokenProperties),
  482. 'check' => self::returnValidation($mvs[0]),
  483. 'notes' => $notes
  484. );
  485.  
  486. // 2. Color upholstery
  487. $notes = '';
  488. if (isset($color_upholstery[1])) {
  489. foreach ($color_upholstery[1] as $msg) {
  490. $notes .= \Util::txtAPI("offer validate - $msg", $this->tokenProperties) . '\n';
  491. }
  492. }
  493.  
  494. $sections[] = array(
  495. 'name' => \Util::txtAPI('offer validate - color upholstery', $this->tokenProperties),
  496. 'check' => self::returnValidation($color_upholstery[0]),
  497. 'notes' => $notes
  498. );
  499.  
  500. // 3. Optionals
  501. $notes = '';
  502. if (isset($optionals[1])) {
  503. foreach ($optionals[1] as $msg) {
  504. $notes .= \Util::txtAPI("offer validate - $msg", $this->tokenProperties) . '\n';
  505. }
  506. }
  507.  
  508. $sections[] = array(
  509. 'name' => \Util::txtAPI('offer validate - optionals', $this->tokenProperties),
  510. 'check' => self::returnValidation($optionals[0]),
  511. 'notes' => $notes
  512. );
  513.  
  514. // 4. Accessories
  515. $notes = '';
  516. if ($hasAccessories) {
  517. foreach ($accessories[1] as $msg) {
  518. $notes .= \Util::txtAPI("offer validate - $msg", $this->tokenProperties) . '\n';
  519. }
  520. }
  521.  
  522. $sections[] = array(
  523. 'name' => \Util::txtAPI('offer validate - accessories', $this->tokenProperties),
  524. 'check' => $hasAccessories ? self::returnValidation($accessories[0]) : 0,
  525. 'notes' => $notes
  526. );
  527.  
  528. // 5. Availability
  529. $sections[] = array(
  530. 'name' => \Util::txtAPI('offer validate - availability', $this->tokenProperties),
  531. 'check' => $_SESSION['SS_FLAGSHIP_DEALER'] ? 1 : 0,
  532. 'notes' => $_SESSION['SS_FLAGSHIP_DEALER'] ? \Util::txtAPI(
  533. "NOT_LOCAL_STOCK_CHECK_STATUS_IN_SAP", $this->tokenProperties) : \Util::txtAPI(
  534. "VEHICLE_NOT_IN_STOCK", $this->tokenProperties)
  535. );
  536.  
  537. // 6. Used
  538. $sections[] = array(
  539. 'name' => \Util::txtAPI('offer validate - used', $this->tokenProperties),
  540. 'check' => $hasUsed ? 1 : 0,
  541. 'notes' => $hasUsed ? \Util::txtAPI("offer validate - controllare usato",
  542. $this->tokenProperties) : \Util::txtAPI("offer validate - usato non presente",
  543. $this->tokenProperties)
  544. );
  545.  
  546. // 7. Financing
  547. $sections[] = array(
  548. 'name' => \Util::txtAPI('offer validate - financing', $this->tokenProperties),
  549. 'check' => $hasFinancing ? 1 : 0,
  550. 'notes' => $hasFinancing ? \Util::txtAPI("offer validate - controllare finanziamento",
  551. $this->tokenProperties) : \Util::txtAPI(
  552. "offer validate - finanziamento non presente", $this->tokenProperties)
  553. );
  554.  
  555. // 8. Offer
  556. $notes = '';
  557. if (isset($summary[1])) {
  558. foreach ($summary[1] as $msg) {
  559. $notes .= \Util::txtAPI("offer validate - $msg", $this->tokenProperties) . '\n';
  560. }
  561. }
  562.  
  563. $sections[] = array(
  564. 'name' => \Util::txtAPI('offer validate - offer', $this->tokenProperties),
  565. 'check' => self::returnValidation($summary[0]),
  566. 'notes' => $notes
  567. );
  568.  
  569. $models[] = array(
  570. 'codoffer' => $codoffer,
  571. 'sections' => $sections
  572. );
  573.  
  574. $c = new QuotationCollection();
  575. foreach ($models as $item) {
  576. // $q = new QuotationEntity($item);
  577. $c->add($item);
  578. }
  579.  
  580. return $c;
  581. }
  582.  
  583. /**
  584. * Richiede la duplicazione di un'offerta.
  585. * Se ha successo ritorna una nuova QuotationEntity.
  586. *
  587. * @see OfferPathController
  588. *
  589. * @param string $codoffer
  590. */
  591. public function duplicateQuotation($codoffer)
  592. {
  593. $debug = $pippo;
  594.  
  595. $_GET['id_sesion_sr'] = $codoffer;
  596.  
  597. // carichiamo l'OfferController che usiamo come DAO...
  598. $offerPathController = new \OfferPathController();
  599.  
  600. $offerPathController->viewType = 0;
  601. $offerPathController->changeViewType = 1;
  602. $offerPathController->action = 'modality';
  603. $offerPathController->mode = 'duplicate';
  604. $offerPathController->isAPI = 1;
  605.  
  606. // $offerController->setProperties(); // ritorna un 404
  607.  
  608. // attualizziamo l'offerta, da verificare se serve
  609. $new_codoffer = $offerPathController->process(true);
  610.  
  611. self::addOMobileOffer($codoffer, $new_codoffer);
  612.  
  613. return self::getQuotation($new_codoffer);
  614. }
  615.  
  616. private function addOMobileOffer($codoffer, $new_codoffer) {
  617. require_once APPL_PATH . 'COMMON/classes/MobileOffer.class.php';
  618. $res = \MobileOffer::findByPrimaryKey($codoffer);
  619. $offermobile = 'IP';
  620. $url_photo = '';
  621. $appsource = '';
  622.  
  623. if (empty($res)) {
  624. \MobileOffer::insertoffer($codoffer, $offermobile, 0, $url_photo, $appsource);
  625. \MobileOffer::insertoffer($new_codoffer, $offermobile, 0, $url_photo, $appsource);
  626. } else {
  627. if (empty($url_photo) && !empty($res[0]['URL_PHOTO'])) {
  628. $url_photo = $res[0]['URL_PHOTO'];
  629. }
  630. if (empty($appsource) && !empty($res[0]['APPSOURCE'])) {
  631. $appsource = $res[0]['APPSOURCE'];
  632. }
  633.  
  634. //\MobileOffer::updateoffer($codoffer, $res[0]['PRICE'], $url_photo, $appsource);
  635. \MobileOffer::insertoffer($new_codoffer, $offermobile, $res[0]['PRICE'], $url_photo, $appsource);
  636. }
  637. }
  638.  
  639. /**
  640. * Ritorna il numero massimo di giorni di validità dell'offerta.
  641. *
  642. * ripreso da oracle.showroom.loc/offer_validity_layer.php
  643. *
  644. * @param int $codoffer
  645. * @return int numero di giorni di validità dell'offerta
  646. */
  647. public function getOfferValidity($codoffer)
  648. {
  649. if (empty($this->offer)) {
  650. // inizializzazione delle variabili d'ambiente
  651. $this->initSession($codoffer);
  652. }
  653.  
  654. require_once (APPL_PATH . 'oracle.showroom.loc/class/Dealer.class.php');
  655. $concesionario = new \Dealer();
  656.  
  657. // DEALER MAX VALIDITY
  658. $concesionario->findDealerByPrimaryKey($_SESSION['SS_CODMARKET'], $_SESSION['SS_CODDEALER']);
  659. $maxOfferValidity = $concesionario->getDaysOfferValid();
  660.  
  661. if (empty($maxOfferValidity)) {
  662. $maxOfferValidity = 30;
  663. }
  664.  
  665. // B3378 (this check block)
  666. if ($_SESSION['SS_CODMARKET'] == MARKET_NL) {
  667. if ($maxOfferValidity > 14) {
  668. $maxOfferValidity = 14;
  669. }
  670. }
  671.  
  672. // normalmente la validità dell'offerta è sono i giorni mancanti al fine mese
  673. $offerValidity = date('t') - date('j');
  674.  
  675. // se siamo nell'ultimo giorno del mese impostiamo a 1
  676. if ($offerValidity == 0) {
  677. $offerValidity = 1;
  678. }
  679. // se abbiamo un limite più stringente lo applichiamo
  680. if ($offerValidity > $maxOfferValidity) {
  681. $offerValidity = $maxOfferValidity;
  682. }
  683. /**
  684. * array (schiantato in offer_validity_layer.php) dei mercati
  685. * che vogliono offervalidity=maoffervalidity
  686. */
  687. $arr[] = MARKET_AT;
  688. $arr[] = MARKET_CH;
  689. $arr[] = MARKET_PL;
  690. $arr[] = MARKET_FR;
  691. $arr[] = MARKET_DE;
  692. if (in_array($_SESSION['SS_CODMARKET'], $arr)) {
  693. $offerValidity = $maxOfferValidity;
  694. }
  695. return $offerValidity;
  696. }
  697.  
  698. /**
  699. * setOfferValidity
  700. *
  701. * @see /post_conf_pago.php?next=&validez=13&dms=&codoffer=73738856&validez_maxima=30
  702. *
  703. * @param string $codOffer
  704. * @param integer $validez
  705. */
  706. public function setOfferValidity($codoffer, $validez, $status = 0)
  707. {
  708. // verifichiamo che l'offerta non sia completa
  709. if ($status == 0 && $this->offer->offerstate) {
  710. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  711. }
  712.  
  713. $sesionShowroom = new \SesionShowroom();
  714. $sesionShowroom->findByPrimaryKey($codoffer);
  715.  
  716. /**
  717. * BUG 9696.
  718. * Modifiche perse che riguardano il T1493
  719. */
  720. if ($_SESSION['SS_CODMARKET'] == MARKET_NL) {
  721. if ($_SESSION['SS_CUSTOMER_TYPE'] == 'C') // [FG TASK 1802] sostituzione codici R1 con R2 e variabile di sessione
  722. $viewType = 1;
  723. else
  724. $viewType = 0;
  725.  
  726. $_SESSION['SS_OFFER_VIEW_TYPE'] = $viewType;
  727. $sesionShowroom->setVisualizationType($viewType);
  728. }
  729. /**
  730. * END BUG 9696 *
  731. */
  732.  
  733. $sesionShowroom->setValidez($validez);
  734.  
  735. // Per tutti mercati la offerta viene chiusa qui (OFFERSTATUS = 1), invece per prima lo faceva r2.propuesta con la funzione tryClose.
  736. //$sesionShowroom->setCerrado("NU");
  737.  
  738. $res = $sesionShowroom->store();
  739.  
  740. return $res;
  741. }
  742.  
  743. /**
  744. * stampa:
  745. * /offer/offer_printed.php
  746. *
  747. * invio mail:
  748. * /offer/ajax/sendmail_ajax_call.php
  749. *
  750. * mopar:
  751. * /offer/view/offer_print_mopar_section.tpl.php
  752. *
  753. * @sample
  754. * /offer/offer_printed.php?printable=yes&reanudar=&detalle=&idioma=&notax=no&smart=3&pageBreaks=[]
  755. *
  756. * @param string $codoffer
  757. */
  758. public function submitOffer($data)
  759. {
  760. $codoffer = $data->codoffer;
  761. $sendmail = !empty($data->sendmail) ? $data->sendmail : 0;
  762. $validity_days = !empty($data->validity_days) ? intval($data->validity_days) : 0;
  763.  
  764. $createocf = !empty($data->createOcf) ? $data->createOcf : 0;
  765. $priceprotection = !empty($data->priceprotection) ? $data->priceprotection : null;
  766.  
  767. $lastDayThisMonth = date("t");
  768. $todayDayThisMonth = date("j");
  769. $dayDifference = $lastDayThisMonth - $todayDayThisMonth;
  770.  
  771. if($validity_days == 0 || $validity_days > $dayDifference) {
  772. $validity_days = $dayDifference;
  773. }
  774.  
  775. $ocfnumber = null;
  776.  
  777. $p_codlanguage = $this->tokenProperties['CODLANGUAGE'];
  778. $codnegotiation = !empty($data->codnegotiation) ? $data->codnegotiation : null;
  779. $namenegotiation = !empty($data->namenegotiation) ? $data->namenegotiation : '';
  780. $status = !empty($data->status) ? $data->status : 0;
  781. $note = !empty($data->note) ? $data->note : '';
  782. $tax = strlen($data->tax) ? filter_var($data->tax, FILTER_VALIDATE_BOOLEAN) : false;
  783. $technical_info = strlen($data->technical_info) ? intval($data->technical_info) : 0;
  784. $breakpoint = !empty($data->breakpoint) ? explode(',', $data->breakpoint) : array();
  785.  
  786. self::initSession($codoffer);
  787.  
  788. ### /offer/offer_printed.php
  789. $offerLayoutUeEnable = true; //\MarketParams::findValueByPrimaryKey('OFFERLAYOUT_UE_ENABLE', $_SESSION['SS_CODMARKET'], '', '0');
  790. //$use_iText = \MarketParams::findValueByPrimaryKey("PDF_GENERATOR_ITEXT", $_SESSION['SS_CODMARKET']);
  791. if ($offerLayoutUeEnable) {
  792. switch($_SESSION['SS_CODMARKET']) {
  793. case MARKET_DE:
  794. require_once(APPL_PATH . 'oracle.showroom.loc/offer/controller/OfferPrintedControllerUE_3110.class.php' );
  795. $offerPrintController = new \OfferPrintedControllerUE_3110();
  796. break;
  797. case MARKET_TR:
  798. require_once(APPL_PATH . 'oracle.showroom.loc/offer/controller/OfferPrintedControllerUE_3239.class.php' );
  799. $offerPrintController = new \OfferPrintedControllerUE_3239();
  800. break;
  801. /*
  802. case MARKET_HU:
  803. require_once(APPL_PATH . 'oracle.showroom.loc/offer/controller/OfferPrintedControllerUE_3129.class.php' );
  804. $offerPrintController = new \OfferPrintedControllerUE_3129();
  805. break;
  806. */
  807. default:
  808. //require_once(APPL_PATH . 'oracle.showroom.loc/offer/controller/OfferPrintedControllerUE.class.php' );
  809. $offerPrintController = new \OfferPrintedControllerUE();
  810. }
  811. } else {
  812. //require_once(APPL_PATH . 'oracle.showroom.loc/offer/controller/OfferPrintedController.class.php' );
  813. //$offerPrintController = new \OfferPrintedController();
  814. $offerPrintController = new \OfferPrintedControllerUE();
  815. }
  816.  
  817. // OFFER PRINT CONTROLLER
  818. $offerPrintController->printable = 'yes';
  819. $offerPrintController->isAjax = 1;
  820. $offerPrintController->isAPI = 1;
  821. $offerPrintController->sendpdf = ($sendmail && $status) ? 1 : 0;
  822. $offerPrintController->status = $status;
  823. $offerPrintController->pageBreaks = $breakpoint;
  824. $offerPrintController->setProperties();
  825.  
  826. // attualizziamo l'offerta, da verificare se serve
  827. $offerPrintController->process(true);
  828. $offerPrintController->load();
  829.  
  830. //$url_pdf = $offerPrintController->display(); // ritorna l'url del pdf (pdfoutput_footer.inc.php).
  831.  
  832. if($status == 1 && $sendmail == 1 && is_null($offerPrintController->userObj->getEmail())) {
  833. return new BaseException(BaseException::PROCESS_ERROR, "mailfrom could not be empty!");
  834. }
  835.  
  836. // inizializzazione delle variabili d'ambiente
  837. $this->initSession($codoffer);
  838.  
  839. $offerController = new \OfferController();
  840.  
  841. $offerController->viewType = 0;
  842. $offerController->changeViewType = 1;
  843. $offerController->codoffer = $codoffer;
  844.  
  845. // attualizziamo l'offerta
  846. $offerController->process(true);
  847.  
  848. if ($status == 1) {
  849. require_once APPL_PATH . 'COMMON/classes/iLinkApp.class.php';
  850. \iLinkApp::insertOfferOnQuotation($codoffer, $sendmail, $technical_info);
  851. }
  852.  
  853. $offer = self::getOffer();
  854.  
  855. if($_SESSION['SS_CODMARKET'] == MARKET_TR) {
  856.  
  857. $offerPrintController->notes = $note;
  858.  
  859. $this->profitability_free = null;
  860. $this->profitability_stock = null;
  861.  
  862. $offerAddonTrk = \OfferBase::findOfferAddonTrkByPrimaryKey($this->codoffer);
  863.  
  864. $profitabilityfree_ratio = $offerController->tplOffer['profitabilityfree_ratio'];
  865. $profitabilityfree_value = $offerController->tplOffer['profitabilityfree_value'];
  866. $profitabilitystock_ratio = $offerController->tplOffer['profitabilitystock_ratio'];
  867. $profitabilitystock_value = $offerController->tplOffer['profitabilitystock_value'];
  868.  
  869. $deliverydate = !empty($offerAddonTrk[0]['DELIVERYDATE']) ? $offerAddonTrk[0]['DELIVERYDATE'] : null;
  870. $insuranceamount = !empty($offerAddonTrk[0]['INSURANCEAMOUNT']) ? $offerAddonTrk[0]['INSURANCEAMOUNT'] : 0;
  871. $trafficinsurance = !empty($offerAddonTrk[0]['TRAFFICINSURANCE']) ? $offerAddonTrk[0]['TRAFFICINSURANCE'] : 0;
  872. $statusvehicle = "Conf tool";
  873.  
  874. if (!empty($this->codorder)) {
  875.  
  876. $trkStock = \TRK_Stock::find_stockByCodfactoryorder($this->codorder, $this->tokenProperties['CODLANGUAGE']);
  877.  
  878. if (count($trkStock) > 0) {
  879.  
  880. if (!empty($trkStock[0]['INVOICEDATE']) && ($trkStock[0]['SECONDARY_STATUS']!='SW10' && $trkStock[0]['SECONDARY_STATUS']!='SW20') && $trkStock[0]['PRICETODEALER']) {
  881.  
  882. $profitstockloss = ($profitabilitystock_value > 0) ? "OP" : "OL";
  883.  
  884. $profitabilitystockPercentage = (($profitabilitystock_ratio) * 100);
  885.  
  886. if($profitabilitystockPercentage < 0) {
  887. $profitabilitystockPercentage *= -1;
  888. }
  889.  
  890. $profitabilityStringStock = "LINK-NOM-" . str_replace(".", ",", sprintf("%.2f", abs($profitabilitystock_value))) . "-" . str_replace(".", ",", sprintf("%.2f", $profitabilitystockPercentage)) . "-" . $profitstockloss;
  891.  
  892. $this->profitability_stock = $profitabilityStringStock;
  893.  
  894. $dealerBase = \DealerBase::findByPrimaryKeyDealer($trkStock[0]['CODMARKET'], $trkStock[0]['CODDEALER']);
  895.  
  896. if ($dealerBase[0]['CODMAINDEALER'] == $this->tokenProperties['CODDEALER']) {
  897. $statusvehicle = "Invoiced";
  898. } else {
  899. $statusvehicle = "Invoiced other dealer";
  900. }
  901.  
  902. } else {
  903. $statusvehicle = "Uninvoiced";
  904. }
  905.  
  906. }
  907.  
  908. }
  909.  
  910. $profitfreeloss = ($profitabilityfree_value > 0) ? "OP" : "OL";
  911.  
  912. $profitabilityfreePercentage = (($profitabilityfree_ratio) * 100);
  913.  
  914. if($profitabilityfreePercentage < 0) {
  915. $profitabilityfreePercentage *= -1;
  916. }
  917.  
  918. $profitabilityStringFree = "LINK-CUR-" . str_replace(".", ",", sprintf("%.2f", abs($profitabilityfree_value))) . "-" . str_replace(".", ",", sprintf("%.2f",$profitabilityfreePercentage)) . "-" . $profitfreeloss;
  919.  
  920. $this->profitability_free = $profitabilityStringFree;
  921.  
  922. $result = \OfferBase::storeOfferAddonTrk($codoffer, $statusvehicle, $deliverydate, $insuranceamount, $trafficinsurance, $profitabilityfree_ratio, $profitabilityfree_value, $profitabilitystock_ratio, $profitabilitystock_value, null, null, null);
  923.  
  924. if ($result < 0) {
  925. return new BaseException(BaseException::PROCESS_ERROR, "Offer " . $codoffer . " error!");
  926. }
  927.  
  928. if ($status == 1 && $createocf == 1) {
  929.  
  930. $ocfmodel = new \OcfModel();
  931. $ocfmodel->codmarket = $_SESSION['SS_CODMARKET'];
  932. $ocfmodel->loginname = $_SESSION['SS_LOGINNAME'];
  933. $ocfmodel->codlanguage = $_SESSION['SS_CODLANGUAGE'];
  934. $ocfmodel->codfactoryorder = $offer->codorder;
  935. $ocfmodel->ocfpriceprotected = $priceprotection;
  936. $ocfmodel->codoffer = $codoffer;
  937. $ocfmodel->codsalesman = $_SESSION['SS_LOGINNAME'];
  938.  
  939. $userData = \ElinkUser::findUserbyPk($_SESSION['SS_CODMARKET'],
  940. $this->tokenProperties['LOGINNAME']);
  941. if (!$userData)
  942. throw new \Exception("UserData not found!");
  943.  
  944. $ocfmodel->lastname = $userData[0]['LASTNAME'];
  945.  
  946. $result = $ocfmodel->confirmOcf();
  947.  
  948. if(!$result['success']) {
  949. return new BaseException(BaseException::PROCESS_ERROR, "OCF create error!");
  950. }
  951.  
  952. $ocfnumber = explode("-", $result["data"])[0];
  953. }
  954.  
  955. }
  956.  
  957. // ## Scheda Tecnica ###
  958. if ($technical_info == 1) {
  959. $_REQUEST['schedaTecnica'] = 'S';
  960. $_REQUEST['fileNameFicha'] = '';
  961. }
  962.  
  963. // verifichiamo che l'offerta non sia completa
  964. if ($offer->getOfferState()) {
  965. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  966. }
  967.  
  968. if (!empty($codnegotiation) || !empty($namenegotiation)) {
  969. self::createNegotiation($codoffer, $codnegotiation, $namenegotiation);
  970. }
  971.  
  972. // STAMPA PDF
  973. $_SESSION['SS_OFFER_VIEW_TYPE'] = $tax;
  974.  
  975. ### CALCOLATRICE FINANZIARIA: Sviluppata nella CR4067 testata per mercati GR 3113, NL 3122, SE 3127...
  976. if (in_array($_SESSION["SS_CODMARKET"], array(MARKET_GR, MARKET_NL, MARKET_SE))) {
  977. // carichiamo l'OfferSummaryController che usiamo come DAO...
  978. $offerSummaryController = new \OfferSummaryController();
  979.  
  980. $offerSummaryController->changeViewType = $tax ? 1 : 0;
  981. $offerSummaryController->viewType = $tax ? 1 : 0; // 0 = normal (TAX); 1 = detailed (DETAX)
  982. $offerSummaryController->isAPI = 1;
  983.  
  984. $offerSummaryController->setProperties();
  985. // attualizziamo l'offerta
  986. $offerSummaryController->process();
  987. $offerSummaryController->display();
  988. //var_dump($_SESSION["CAR_PRICE"] .' - '. $_SESSION["CAR_PRICEDETAX"]); die;
  989. }
  990.  
  991. if ($validity_days > 0) {
  992. self::setOfferValidity($codoffer, $validity_days, $status);
  993. }
  994.  
  995. if($status) {
  996. $offer->setOfferState($status);
  997. }
  998.  
  999. $offer->setNotes($note);
  1000. $offer->setDayValidityPeriod($validity_days);
  1001. $offer->store();
  1002.  
  1003. $url_pdf = $offerPrintController->display(); // ritorna l'url del pdf (pdfoutput_footer.inc.php).
  1004.  
  1005. $pdf = \Util::getProtocol() . '://' . $_SERVER['HTTP_HOST'] . $url_pdf;
  1006.  
  1007. $quotation = new QuotationEntity(null);
  1008. $quotation->codoffer = $codoffer;
  1009. $quotation->pdf = $pdf;
  1010.  
  1011. if(!empty($ocfnumber)) {
  1012. $quotation->ocfnumber = $ocfnumber;
  1013. }
  1014.  
  1015. if ($offerPrintController->sendpdf || !empty($email)) {
  1016.  
  1017. // ## Scheda Tecnica ###
  1018. if ($technical_info == 1) {
  1019. $_REQUEST['schedaTecnica'] = 'S';
  1020. $_REQUEST['fileNameFicha'] = '';
  1021. $_GET['printable'] = 'yes';
  1022. $_GET['send_ficha_crm'] = 1;
  1023.  
  1024. unset($_GET['isAjax']);
  1025.  
  1026. ob_start();
  1027. require_once APPL_PATH . 'oracle.showroom.loc/ficha_tecnica.php';
  1028. $data = ob_get_clean();
  1029. }
  1030.  
  1031. // ## Invio Mail ###
  1032. $_REQUEST['mailfrom'] = $offerPrintController->userObj->getEmail();
  1033. $_REQUEST['mailto'] = !empty($email) ? $email : $offerPrintController->contactObj->getEmail();
  1034. $_REQUEST['contactname'] = $offerPrintController->contactname;
  1035. $_REQUEST['filename'] = urlencode($offerPrintController->modeloObj->getNombre());
  1036.  
  1037. if (file_exists(APPL_PATH . 'oracle.showroom.loc/offer/ajax/sendmail_ajax_call.php')) {
  1038. require_once APPL_PATH . 'oracle.showroom.loc/offer/ajax/sendmail_ajax_call.php';
  1039. }
  1040.  
  1041. }
  1042.  
  1043. return $quotation;
  1044. }
  1045.  
  1046. /**
  1047. * Verifica se il veicolo usato selezionato è cambiato, ne imposta
  1048. * il valore e lo associa alla quotazione.
  1049. *
  1050. * I parametri sono validati dal chiamante
  1051. *
  1052. * @param string $codoffer
  1053. * @param string $codUsed
  1054. * @param float $value
  1055. * @param float $taxAmount imporo complessivo kanten per NL
  1056. * @param float $taxAmountStanding residuo Kanten per NL
  1057. * @param string $modality non utilizzato, mantenuto per usi futuri
  1058. * @return QuotationEntity
  1059. */
  1060. public function setSaleChannel($codoffer, $codchannel)
  1061. {
  1062. // verifichiamo che l'offerta non sia completa
  1063. if ($this->offer->offerstate) {
  1064. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1065. }
  1066.  
  1067. $offer = new \Offer();
  1068. $result = $offer->setSaleChannel($codoffer, $codchannel);
  1069.  
  1070. if(!$result) {
  1071. return new BaseException(BaseException::PROCESS_ERROR,
  1072. "Error storing codchannel {$codchannel} of Offer {$codoffer}.");
  1073. }
  1074.  
  1075. return $this->getQuotation($codoffer);
  1076.  
  1077. }
  1078.  
  1079. public function setSpecialSalesRequest($codoffer, $idrequest)
  1080. {
  1081.  
  1082. // verifichiamo che l'offerta non sia completa
  1083. if ($this->offer->offerstate) {
  1084. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1085. }
  1086.  
  1087. $offer = new \Offer();
  1088.  
  1089. if($offer->findByPrimaryKey($codoffer)) {
  1090.  
  1091. $this->setOffer($offer);
  1092.  
  1093. $promotion = TRK_SpecialSales::findPromobySSrequestDetail($idrequest, $this->tokenProperties['CODLANGUAGE']);
  1094.  
  1095. if(count($promotion) > 0) {
  1096.  
  1097. foreach ($promotion as $item) {
  1098.  
  1099. if($item['MVSSPE'] == $offer->getCodModel() . "." . $offer->getCodVersion() . "." . $offer->getCodSerie() . "." . $offer->getCodSpecialSerie()) {
  1100. $this->setPromotion($codoffer, $item['CODPROMOTION']);
  1101. }
  1102.  
  1103. }
  1104.  
  1105. }
  1106.  
  1107. $addDiscount = TRK_SpecialSales::getAddDiscByMVSS($idrequest, $offer->getCodBrand(), $offer->getCodModel() . "." . $offer->getCodVersion() . "." . $offer->getCodSerie() . "." . $offer->getCodSpecialSerie(), null);
  1108.  
  1109. if($addDiscount != 0) {
  1110. $this->setDealerFreeService($codoffer, "TRKPROMO", $addDiscount . "%", 'tax', 0, 1);
  1111. }
  1112.  
  1113. $result = $offer->setSpecialSalesRequest($codoffer, $idrequest);
  1114.  
  1115. if(!$result) {
  1116. return new BaseException(BaseException::PROCESS_ERROR,
  1117. "Error storing requestid {$idrequest} of Offer {$codoffer}.");
  1118. }
  1119.  
  1120. }
  1121.  
  1122.  
  1123. return $this->getQuotation($codoffer);
  1124.  
  1125. }
  1126.  
  1127. /**
  1128. * Verifica se il veicolo usato selezionato è cambiato, ne imposta
  1129. * il valore e lo associa alla quotazione.
  1130. *
  1131. * I parametri sono validati dal chiamante
  1132. *
  1133. * @param string $codoffer
  1134. * @param string $codUsed
  1135. * @param float $value
  1136. * @param float $taxAmount imporo complessivo kanten per NL
  1137. * @param float $taxAmountStanding residuo Kanten per NL
  1138. * @param string $modality non utilizzato, mantenuto per usi futuri
  1139. * @return QuotationEntity
  1140. */
  1141. public function setTradeInValue($codoffer, $codUsedVehicle, $value, $taxAmount = null,
  1142. $taxAmountStanding = null, $modality = null)
  1143. {
  1144. // verifichiamo che l'offerta non sia completa
  1145. if ($this->offer->offerstate) {
  1146. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1147. }
  1148.  
  1149. $changedVehicle = (bool) ($this->offer->codusedvehicle != $codUsedVehicle);
  1150.  
  1151. $usedVehicle = new \UsedVehicle();
  1152. $usedVehicle->loadOfferUsedVehicle();
  1153.  
  1154. if ($changedVehicle) {
  1155. // notare che la findByPrimaryKey ritorna una collezione di oggetti...
  1156. $res = $usedVehicle->findByPrimaryKey($codUsedVehicle,
  1157. $this->tokenProperties['CODLANGUAGE']);
  1158. if (count($res) == 0) {
  1159. return new BaseException(BaseException::PROCESS_ERROR,
  1160. "Trade-in vehicle {$codUsedVehicle} not found!");
  1161. }
  1162. // popolo l'attributo offer (che sarebbe un OfferUsedVehicle utilizzando
  1163. // il primo UsedVehicle trovato castandolo ad array
  1164. $usedVehicle->offer->loadDBRecord((array) $res[0]);
  1165. // valorizza l'attributo codoffer dell'OfferUsedVehicle
  1166. $usedVehicle->offer->codoffer = $codoffer;
  1167. } else {
  1168. $usedVehicle->offer->findByCodOffer($codoffer);
  1169. }
  1170. $usedVehicle->offer->setmodifiedprice(abs($value));
  1171.  
  1172. if(!$usedVehicle->offer->storeOfferUsedVehicle()) {
  1173. return new BaseException(BaseException::PROCESS_ERROR,
  1174. "Error storing Trade-in vehicle {$codUsedVehicle} of Offer {$codoffer}.");
  1175. }
  1176.  
  1177. return self::getQuotation($codoffer);
  1178. }
  1179.  
  1180. /**
  1181. * Imposta il prezzo finale dell'offerta calcolando lo sconto da applicare
  1182. * per ottenere il valore desiderato.
  1183. * Nasce per il mercato Austria.
  1184. * Potrebbe applicarsi anche ad altri mercati?
  1185. * vedi offer_summary_detail_3103.tpl.php, offer_summary.js, discountedPrice.js
  1186. *
  1187. * @param string $codoffer
  1188. * @param float $finalPrice prezzo lordo finale desiderato (compreso tasse)
  1189. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1190. */
  1191. public function setFinalPrice($codoffer, $finalPrice)
  1192. {
  1193. // inizializzazione delle variabili d'ambiente
  1194. $this->initSession($codoffer);
  1195.  
  1196. // carichiamo l'OfferController che usiamo come DAO...
  1197. $offerController = new \OfferController();
  1198.  
  1199. $offerController->viewType = 0;
  1200. $offerController->changeViewType = 1;
  1201. $offerController->codoffer = $codoffer;
  1202.  
  1203. // attualizziamo l'offerta
  1204. $offerController->process(true);
  1205.  
  1206. // il calcolo dello sconto implica una formula che andrebbe gestita tramite
  1207. // PriceEngine...
  1208.  
  1209. // è accettabile solo una riduzione del prezzo
  1210. if ($finalPrice < $offerController->tplOffer['total_pagare_ivato']) {
  1211.  
  1212. $offertafinaleSoloIvato = $offerController->tplVehicle['taxedPrice_PC'] +
  1213. $offerController->tplOffer['optsoloivato'];
  1214. $differBase = -$offerController->tplOffer['differbase'];
  1215. $novaPerc = $offerController->tplOffer['nova'];
  1216. $iva = $offerController->tplOffer['iva'];
  1217.  
  1218. $prezzop1 = $differBase / ($novaPerc / 100);
  1219. $d44 = $offertafinaleSoloIvato / (1 + $iva);
  1220. $prezzop2 = ($d44 - $prezzop1) * (1 + $iva);
  1221. $totExtraProduct = $offerController->tplOffer['extrasNoNovaTotal']['taxedPrice'] +
  1222. $offerController->tplOffer['extrasNovaTotal']['taxedPrice'];
  1223.  
  1224. if ($prezzop2 > $finalPrice) {
  1225. // p2>PF
  1226. $sconto = ($finalPrice - $offertafinaleSoloIvato - $totExtraProduct) / (1 + $iva);
  1227. } else {
  1228. $sconto = -((($offertafinaleSoloIvato + $totExtraProduct + ($differBase)) -
  1229. $finalPrice) / ((1 + $iva) + ($novaPerc / 100)));
  1230. }
  1231. // lo sconto in Austria viene comunque applicato senza tasse
  1232. return self::setDealerFreeService($codoffer, 'Rabatt auf den Endpreis berechnet',
  1233. $sconto, 'detax');
  1234. }
  1235.  
  1236. return self::getQuotation($codoffer);
  1237. }
  1238.  
  1239. /**
  1240. * Remove the vehicle from the current offer.
  1241. *
  1242. * @see removeUsedVehicleHandler (OfferSummaryController.class.php)
  1243. *
  1244. * @param string $codoffer
  1245. */
  1246. public function deleteTradeInValue($codoffer)
  1247. {
  1248. $usedVehicle = new \UsedVehicle();
  1249. $usedVehicle->loadOfferUsedVehicle();
  1250. $usedVehicle->removeUsedVehicleFromOffer($codoffer);
  1251.  
  1252. return self::getQuotation($codoffer);
  1253. }
  1254.  
  1255. /**
  1256. * Associa una clientela speciale all'offerta e ritorna un oggetto QuotationEntity aggiornato.
  1257. *
  1258. * @param string $codoffer
  1259. * @param string $codcustomertype
  1260. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1261. * @throws \Exception
  1262. */
  1263. public function setSpecialCustomer($codoffer, $codcustomertype)
  1264. {
  1265. // verifichiamo che l'offerta non sia completa
  1266. if ($this->offer->offerstate) {
  1267. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1268. }
  1269.  
  1270. try {
  1271. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1272. $offerSummaryController = new \OfferSummaryController();
  1273.  
  1274. // forziamo gli attributi necessari all'azione
  1275. $offerSummaryController->doAction = 'add_extra'; // -> addExtraHandler
  1276.  
  1277. $offerSummaryController->extraType = 3; // -> addVipDiscounts
  1278. $offerSummaryController->changeViewType = 1;
  1279. $offerSummaryController->viewType = 1; // 0 = normal (TAX); 1 = detailed (DETAX)
  1280. $offerSummaryController->extraCode = $codcustomertype;
  1281. $offerSummaryController->isAPI = 1;
  1282.  
  1283. $offerSummaryController->setProperties();
  1284. // attualizziamo l'offerta
  1285. $offerSummaryController->process();
  1286.  
  1287. if ($offerSummaryController->showJavascriptAlerts)
  1288. return new BaseException(BaseException::PROCESS_ERROR,
  1289. $offerSummaryController->javascriptAlertMessages[0]);
  1290.  
  1291. return self::getQuotation($codoffer);
  1292. } catch (\Exception $e) {
  1293. return new BaseException(BaseException::PROCESS_ERROR, $e->getMessage());
  1294. }
  1295. }
  1296.  
  1297. /**
  1298. * Metodo specifico per mercato Olanda
  1299. * Associa una clientela speciale all'offerta e ritorna un oggetto QuotationEntity aggiornato.
  1300. *
  1301. * @param string $codoffer
  1302. * @param string $customercategory
  1303. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1304. * @throws \Exception
  1305. */
  1306. public function setCustomerCategory($codoffer, $customercategory)
  1307. {
  1308. // verifichiamo che l'offerta non sia completa
  1309. if ($this->offer->offerstate) {
  1310. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1311. }
  1312.  
  1313. try {
  1314. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1315. $offerSummaryController = new \OfferSummaryController();
  1316.  
  1317. // forziamo gli attributi necessari all'azione
  1318. $offerSummaryController->doAction = 'switch_customer_category'; // -> addExtraHandler
  1319.  
  1320. $offerSummaryController->extraType = 3; // -> addVipDiscounts
  1321. $offerSummaryController->changeViewType = 0;
  1322. $offerSummaryController->viewType = 1; // 0 = normal (TAX); 1 = detailed (DETAX)
  1323. $offerSummaryController->extraCode = $codcustomertype;
  1324. $offerSummaryController->isAPI = 1;
  1325.  
  1326. $offerSummaryController->setProperties();
  1327. // attualizziamo l'offerta
  1328. $offerSummaryController->process();
  1329.  
  1330. if ($offerSummaryController->showJavascriptAlerts)
  1331. return new BaseException(BaseException::PROCESS_ERROR,
  1332. $offerSummaryController->javascriptAlertMessages[0]);
  1333.  
  1334. return self::getQuotation($codoffer);
  1335. } catch (\Exception $e) {
  1336. return new BaseException(BaseException::PROCESS_ERROR, $e->getMessage());
  1337. }
  1338. }
  1339.  
  1340. /**
  1341. * Remove the given VIPDISCOUNT from the OFFER
  1342. *
  1343. * @param string $codoffer
  1344. * @param string $codcustomertype
  1345. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1346. * @throws \Exception
  1347. */
  1348. public function deleteSpecialCustomer($codoffer, $codcustomertype)
  1349. {
  1350. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1351. $offerSummaryController = new \OfferSummaryController();
  1352.  
  1353. // forziamo gli attributi necessari all'azione
  1354. $offerSummaryController->doAction = 'remove_extra'; // -> removeExtraHandler
  1355.  
  1356. $offerSummaryController->extraType = 3; // -> removeVipDiscounts
  1357. $offerSummaryController->changeViewType = 1;
  1358. $offerSummaryController->viewType = 1; // 0 = normal (TAX); 1 = detailed (DETAX)
  1359. $offerSummaryController->extraCode = $codcustomertype;
  1360. $offerSummaryController->isAPI = 1;
  1361.  
  1362. $offerSummaryController->setProperties();
  1363. // attualizziamo l'offerta
  1364. $offerSummaryController->process();
  1365.  
  1366. if ($offerSummaryController->showJavascriptAlerts)
  1367. return new BaseException(BaseException::PROCESS_ERROR,
  1368. $offerSummaryController->javascriptAlertMessages[0]);
  1369.  
  1370. return self::getQuotation($codoffer);
  1371. }
  1372.  
  1373. /**
  1374. * Associa una promozione all'offerta e ritorna un oggetto QuotationEntity aggiornato.
  1375. *
  1376. * @param string $codoffer
  1377. * @param string $codpromotion
  1378. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1379. * @throws \Exception
  1380. */
  1381. public function setPromotion($codoffer, $codPromotion)
  1382. {
  1383. // verifichiamo che l'offerta non sia completa
  1384. if ($this->offer->offerstate) {
  1385. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1386. }
  1387.  
  1388. try {
  1389. //B42226 - applicazone %iva alle promozioni
  1390. $calc_iva = \IlinkPromotion::findByPrimaryKey($codPromotion, $this->tokenProperties['CODLANGUAGE']);
  1391.  
  1392. if($_SESSION['SS_CODMARKET'] == "3239" && count($calc_iva) == 0) {
  1393.  
  1394. $calc_iva = \IlinkPromotion::findByPrimaryKeyNoPv($codPromotion, $this->tokenProperties['CODLANGUAGE']);
  1395.  
  1396. if($calc_iva['MAIN'] == "2") {
  1397. return new BaseException(BaseException::PROCESS_ERROR,
  1398. "Codpromotion " . $codPromotion . " is not compatible to " . $codoffer);
  1399. }
  1400.  
  1401. }
  1402.  
  1403. $iva = $calc_iva[0]['IVAEXCLUDED'];
  1404.  
  1405. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1406. $offerSummaryController = new \OfferSummaryController();
  1407.  
  1408. // forziamo gli attributi necessari all'azione
  1409. $offerSummaryController->doAction = 'add_extra'; // -> addExtraHandler
  1410.  
  1411. $offerSummaryController->extraType = 1; // -> addPromotions
  1412. $offerSummaryController->changeViewType = 1;
  1413. $offerSummaryController->viewType = 1; // 0 = normal (TAX); 1 = detailed (DETAX)
  1414. $offerSummaryController->extraCode = $codPromotion;
  1415. $offerSummaryController->isAPI = 1;
  1416.  
  1417. if($iva == 1){//B42226 - Applicazone IVA (corretta) alle promozioni
  1418. $offerSummaryController->extraValue = $calc_iva[0]['VALUE']*(1+$offerSummaryController->extraIva);
  1419. } else {
  1420. $offerSummaryController->extraValue = $calc_iva[0]['VALUE'];
  1421. }
  1422.  
  1423. $offerSummaryController->setProperties();
  1424. // attualizziamo l'offerta
  1425. $offerSummaryController->process();
  1426.  
  1427. if ($offerSummaryController->showJavascriptAlerts)
  1428. return new BaseException(BaseException::PROCESS_ERROR,
  1429. $offerSummaryController->javascriptAlertMessages[0]);
  1430.  
  1431. return self::getQuotation($codoffer);
  1432.  
  1433. } catch (\Exception $e) {
  1434. return new BaseException(BaseException::PROCESS_ERROR, $e->getMessage());
  1435. }
  1436. }
  1437.  
  1438. /**
  1439. * Remove the given PROMOTION from the OFFER.
  1440. *
  1441. * @param string $codoffer
  1442. * @param string $codPromotion
  1443. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1444. * @throws \Exception
  1445. */
  1446. public function deletePromotion($codoffer, $codPromotion)
  1447. {
  1448. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1449. $offerSummaryController = new \OfferSummaryController();
  1450.  
  1451. // forziamo gli attributi necessari all'azione
  1452. $offerSummaryController->doAction = 'remove_extra'; // -> removeExtraHandler
  1453.  
  1454. $offerSummaryController->extraType = 1; // -> removePromotions
  1455. $offerSummaryController->changeViewType = 1;
  1456. $offerSummaryController->viewType = 1; // 0 = normal (TAX); 1 = detailed (DETAX)
  1457. $offerSummaryController->extraCode = $codPromotion;
  1458. $offerSummaryController->isAPI = 1;
  1459.  
  1460. $offerSummaryController->setProperties();
  1461. // attualizziamo l'offerta
  1462. $offerSummaryController->process();
  1463.  
  1464. if ($offerSummaryController->showJavascriptAlerts)
  1465. return new BaseException(BaseException::PROCESS_ERROR,
  1466. $offerSummaryController->javascriptAlertMessages[0]);
  1467.  
  1468. return self::getQuotation($codoffer);
  1469. }
  1470.  
  1471. /**
  1472. * Associa una categoria IVA speciale all'offerta e
  1473. * ritorna un oggetto QuotationEntity aggiornato.
  1474. *
  1475. * @see addParametricVatHandler (OfferSummaryController.class.php)
  1476. *
  1477. * @param string $codoffer
  1478. * @param string $value
  1479. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1480. * @throws \Exception
  1481. */
  1482. public function setVAT($codoffer, $value)
  1483. {
  1484. // verifichiamo che l'offerta non sia completa
  1485. if ($this->offer->offerstate) {
  1486. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1487. }
  1488.  
  1489. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1490. $offerSummaryController = new \OfferSummaryController();
  1491.  
  1492. $offerSummaryController->doAction = 'add_parametric_vat';
  1493. $offerSummaryController->removeIvaInOperation = 0;
  1494. $offerSummaryController->extraIva = 0.22; // @TODO: da dove si deve ricavare?
  1495. $offerSummaryController->codCategory = $value;
  1496. $offerSummaryController->extra_id = 0;
  1497.  
  1498. $offerSummaryController->changeViewType = 1;
  1499. $offerSummaryController->viewType = 1;
  1500.  
  1501. $offerSummaryController->setProperties();
  1502. // attualizziamo l'offerta
  1503. $offerSummaryController->process();
  1504.  
  1505. return self::getQuotation($codoffer);
  1506. }
  1507.  
  1508. /**
  1509. * Aggiorna la Kosten legata all'offert Olanda e
  1510. * ritorna un oggetto QuotationEntity aggiornato.
  1511. *
  1512. * @see
  1513. *
  1514. *
  1515. *
  1516. *
  1517. * @param string $codoffer
  1518. * @param string $value
  1519. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1520. * @throws \Exception
  1521. */
  1522. public function setKosten($codoffer, $value)
  1523. {
  1524. // verifichiamo che l'offerta non sia completa
  1525. if ($this->offer->offerstate) {
  1526. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1527. }
  1528.  
  1529. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1530. $offerSummaryController = new \OfferSummaryController();
  1531.  
  1532. $offerSummaryController->doAction = 'update_dealer_tax';
  1533. $offerSummaryController->dealerTaxValue = $value;
  1534. $offerSummaryController->dealerTaxName = 'KOSTEN';
  1535. $offerSummaryController->changeViewType = 1;
  1536. $offerSummaryController->viewType = 1;
  1537.  
  1538. $offerSummaryController->setProperties();
  1539. // attualizziamo l'offerta
  1540. $offerSummaryController->process();
  1541.  
  1542. return self::getQuotation($codoffer);
  1543. }
  1544.  
  1545. /**
  1546. * Associa un IPT all'offerta e ritorna un oggetto QuotationEntity aggiornato.
  1547. *
  1548. * @see changeIptHandler (OfferSummaryController.class.php)
  1549. *
  1550. * @param string $codoffer
  1551. * @param string $value
  1552. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1553. * @throws \Exception
  1554. */
  1555. public function setIpt($codoffer, $value)
  1556. {
  1557. // verifichiamo che l'offerta non sia completa
  1558. if ($this->offer->offerstate) {
  1559. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1560. }
  1561.  
  1562. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1563. $offerSummaryController = new \OfferSummaryController();
  1564.  
  1565. // forziamo gli attributi necessari alla action prima
  1566. // della setProperties perche alcuni sono utilizzati in tale contesto... :P
  1567. $offerSummaryController->doAction = 'change_ipt';
  1568. $params = explode('|', $value);
  1569. $offerSummaryController->codProvince = $params[0];
  1570. if (isset($params[1])) {
  1571. $offerSummaryController->codDestination = $params[1];
  1572. }
  1573. $offerSummaryController->changeViewType = 1;
  1574. $offerSummaryController->viewType = 1;
  1575.  
  1576. $offerSummaryController->setProperties();
  1577. // attualizziamo l'offerta
  1578. $offerSummaryController->process();
  1579.  
  1580. return self::getQuotation($codoffer);
  1581. }
  1582.  
  1583.  
  1584. /**
  1585. * Associa una Register Tax all'offerta e ritorna un oggetto QuotationEntity aggiornato.
  1586. *
  1587. * @see changeIptHandler (OfferSummaryController.class.php)
  1588. *
  1589. * @param string $codoffer
  1590. * @param string $value
  1591. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1592. * @throws \Exception
  1593. */
  1594. public function setRegisterTax($codoffer, $value)
  1595. {
  1596.  
  1597. // verifichiamo che l'offerta non sia completa
  1598. if ($this->offer->offerstate) {
  1599. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1600. }
  1601.  
  1602. if($_SESSION['SS_CODMARKET'] == "3239") {
  1603.  
  1604. if(preg_match('/^\d{4},\d{2},[A-Z]{3}\d{1}?$/', $value)) {
  1605. $value = null;
  1606. }
  1607. $result = \OfferBase::setRegTaxValue($codoffer, $value); // REGTAXVGALUE
  1608. }
  1609.  
  1610. if($result < 0) {
  1611. return new BaseException(BaseException::PROCESS_ERROR, "Register Tax edit error!");
  1612.  
  1613. }
  1614.  
  1615. return self::getQuotation($codoffer);
  1616.  
  1617. }
  1618.  
  1619. /**
  1620. * Associa una Register Tax all'offerta e ritorna un oggetto QuotationEntity aggiornato.
  1621. *
  1622. * @see changeIptHandler (OfferSummaryController.class.php)
  1623. *
  1624. * @param string $codoffer
  1625. * @param string $value
  1626. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1627. * @throws \Exception
  1628. */
  1629. public function setMvt($codoffer, $value)
  1630. {
  1631.  
  1632. // verifichiamo che l'offerta non sia completa
  1633. if ($this->offer->offerstate) {
  1634. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1635. }
  1636.  
  1637. if($_SESSION['SS_CODMARKET'] == "3239") {
  1638. $result = \OfferBase::setMvtValue($codoffer, null);
  1639. } else {
  1640. $result = \OfferBase::setMvtValue($codoffer, $value);
  1641. }
  1642.  
  1643. // $result = \OfferBase::getMvtValue($codoffer); // MVT
  1644. //
  1645. // if(count($result) > 0) {
  1646. //
  1647. // if(is_null($result[0]['MVTVALUE'])) {
  1648. // $result = \OfferBase::setMvtValue($codoffer, 0); // MVT
  1649. // } else {
  1650. // $result = \OfferBase::setMvtValue($codoffer, null); // MVT
  1651. // }
  1652. //
  1653. // } else {
  1654. // $result = \OfferBase::setMvtValue($codoffer, 0); // MVT
  1655. // }
  1656.  
  1657. if($result < 0) {
  1658. return new BaseException(BaseException::PROCESS_ERROR, "Mvt Tax edit error!");
  1659.  
  1660. }
  1661.  
  1662. return self::getQuotation($codoffer);
  1663.  
  1664. }
  1665.  
  1666. /**
  1667. * Associa una Register Tax all'offerta e ritorna un oggetto QuotationEntity aggiornato.
  1668. *
  1669. * @see changeIptHandler (OfferSummaryController.class.php)
  1670. *
  1671. * @param string $codoffer
  1672. * @param string $value
  1673. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1674. * @throws \Exception
  1675. */
  1676. public function setSct($codoffer, $value)
  1677. {
  1678.  
  1679. // verifichiamo che l'offerta non sia completa
  1680. if ($this->offer->offerstate) {
  1681. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1682. }
  1683.  
  1684. $result = \OfferBase::setSctValue($codoffer, $value); // SCT VALUE
  1685.  
  1686. if($result < 0) {
  1687. return new BaseException(BaseException::PROCESS_ERROR, "Sct Tax edit error!");
  1688.  
  1689. }
  1690.  
  1691. return self::getQuotation($codoffer);
  1692.  
  1693. }
  1694.  
  1695. /**
  1696. * ripristina un agenerica tassa preceedentemente azzerata
  1697. *
  1698. * @param string $codoffer
  1699. * @param string $codtax
  1700. */
  1701. public function restoreTax($codoffer, $codtax)
  1702. {
  1703. // verifichiamo che l'offerta non sia completa
  1704. if ($this->offer->offerstate) {
  1705. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1706. }
  1707.  
  1708. $quotationEntity = self::getQuotation($codoffer);
  1709.  
  1710. $canbereset = false;
  1711. /**
  1712. * verifichiamo se la tassa da ripristinare esiste nella quotation
  1713. * serve anche a recuperare il codvalue che viene utilizzato
  1714. * dal controller
  1715. */
  1716. foreach ($quotationEntity->taxes as $tax) {
  1717. if ($tax->codtax == $codtax) {
  1718. $canbereset = $tax->canbereset;
  1719. // trick per superare indenni la setProperties del controller
  1720. // che utilizza nomi diversi delle variabili
  1721. $_POST['codtax'] = $tax->codvalue;
  1722. break; // trovata quella che ci serve è inutile continuare
  1723. }
  1724. }
  1725.  
  1726. if (!$canbereset) {
  1727. return new BaseException(BaseException::PROCESS_ERROR,
  1728. "action restoreTax: tax {$codtax} could not be restored!");
  1729. }
  1730.  
  1731. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1732. $offerSummaryController = new \OfferSummaryController();
  1733.  
  1734. // forziamo gli attributi necessari alla action prima
  1735. // della setProperties perche alcuni sono utilizzati in tale contesto... :P
  1736. $offerSummaryController->changeViewType = 1;
  1737. $offerSummaryController->viewType = 1;
  1738. $offerSummaryController->isAPI = 1;
  1739. /**
  1740. * non ci siamo bevuti il cervello...
  1741. * in OfferSummaryController::taxHandler
  1742. * viene gestita una logica inversa per adattarsi al front-end html
  1743. */
  1744. $offerSummaryController->doAction = 'remove_tax'; // taxHandler
  1745.  
  1746. $offerSummaryController->setProperties();
  1747.  
  1748. // attualizziamo l'offerta
  1749. $offerSummaryController->process();
  1750.  
  1751. return self::getQuotation($codoffer);
  1752. }
  1753.  
  1754. /**
  1755. * Associa un accessorio del concessionario all'offerta e ritorna un oggetto QuotationEntity aggiornato.
  1756. *
  1757. * @see viewAccessors (AccessorsController.class.php)
  1758. *
  1759. * @param string $codoffer
  1760. * @param array $addaccessors
  1761. * @param string $addinstaccessors
  1762. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1763. * @throws \Exception
  1764. */
  1765. public function setDealerAccessory($codoffer, $codaccessory, $onlywork)
  1766. {
  1767. // verifichiamo che l'offerta non sia completa
  1768. if ($this->offer->offerstate) {
  1769. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1770. }
  1771.  
  1772. // 1000_-11830 -> -11830
  1773. $needle = $_SESSION['SS_CODMARKET'] . '_';
  1774. if (preg_match('/' . $needle . '/', $codaccessory)) {
  1775. $codaccessory = str_replace($needle, "", $codaccessory);
  1776. }
  1777.  
  1778. /*
  1779. // TODO: agganciare il costruttore accessori.
  1780. require_once APPL_PATH . 'oracle.showroom.loc/offer/controller/AccessorsController.class.php';
  1781. $accessorController = new \AccessorsController();
  1782.  
  1783. $accessorController->init();
  1784. $accessorController->process();
  1785. */
  1786.  
  1787. $accessors = new \Accessors();
  1788. $accessor = explode(',', $codaccessory);
  1789.  
  1790. $instaccessor = $onlywork == 0 ? $accessor : array();
  1791. //$accessors->removeByCodOffer($codoffer);
  1792. $novaselected = array(); // $this->getNovaSelectedArray();
  1793.  
  1794. for ($a = 0; $a < count($accessor); $a++) {
  1795.  
  1796. if (trim($accessor[$a]) == '')
  1797. continue;
  1798. // Per austria ci sarebbe la variabile novaselected con gli accessori novati
  1799.  
  1800. if (in_array($accessor[$a], $novaselected)) {
  1801. $taxcalc = 1;
  1802. } else {
  1803. $taxcalc = 0;
  1804. }
  1805.  
  1806. if (in_array($accessor[$a], $instaccessor)) {
  1807. $accessors->remove($codoffer, $accessor[$a]);
  1808. $accessors->insertOfferAccessory($accessor[$a], true, $taxcalc,
  1809. $_SESSION['SS_CODBILLCATEGORY']);
  1810. } else {
  1811. $accessors->insertOfferAccessory($accessor[$a], false, $taxcalc,
  1812. $_SESSION['SS_CODBILLCATEGORY']);
  1813. }
  1814. }
  1815.  
  1816. return self::getQuotation($codoffer);
  1817. }
  1818.  
  1819. /**
  1820. * Elimina un accessorio/mano d'opera e ritorna un oggetto QuotationEntity aggiornato.
  1821. *
  1822. * @see viewAccessors (AccessorsController.class.php)
  1823. *
  1824. * @param string $codoffer
  1825. * @param string $codaccessory
  1826. * @return \iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  1827. * @throws \Exception
  1828. */
  1829. public function deleteAccessory($codoffer, $codaccessory, $onlywork)
  1830. {
  1831. // verifichiamo che l'offerta non sia completa
  1832. if ($this->offer->offerstate) {
  1833. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1834. }
  1835.  
  1836. // -11830 -> 1000_-11830
  1837. $needle = $_SESSION['SS_CODMARKET'] . '_';
  1838. if (!preg_match('/' . $needle . '/', $codaccessory)) {
  1839. $codaccessory = $needle . $codaccessory;
  1840. }
  1841.  
  1842. // if ($onlywork == 1)
  1843. {
  1844. require_once APPL_PATH . 'COMMON/classes/class_accesorio_sesion_showroom.php';
  1845. $accessors = new \AccesorioSesionShowroom();
  1846.  
  1847. // $selaccessors = (array) $accessors->findAllByCodOffer($codoffer);
  1848. // var_dump($selaccessors); die;
  1849.  
  1850. $res = $accessors->remove_mo($codoffer, $codaccessory); // carrito_mo
  1851. if ($onlywork == 0) {
  1852. $accessors->remove($codoffer, $codaccessory);
  1853. }
  1854. if ($res) {
  1855. return self::getQuotation($codoffer);
  1856. } else {
  1857. return new BaseException(BaseException::PROCESS_ERROR,
  1858. "deleteAccessory {$codaccessory} failed!");
  1859. }
  1860. }
  1861.  
  1862. /*
  1863. * // Questa soluzione presenta problemi nella rimozione dell'accessorio.
  1864. // $onlywork == 0 cancello tutto.
  1865. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1866. $offerSummaryController = new \OfferSummaryController();
  1867. // forziamo gli attributi necessari all'azione
  1868. $offerSummaryController->doAction = 'remove_accessory'; // -> removeAccessoryHandler
  1869. $offerSummaryController->changeViewType = 1;
  1870. $offerSummaryController->viewType = 1;
  1871. $offerSummaryController->isAPI = 1;
  1872. $offerSummaryController->setProperties();
  1873. // attualizziamo l'offerta
  1874. $offerSummaryController->process();
  1875. if ($offerSummaryController->showJavascriptAlerts)
  1876. return new BaseException(BaseException::PROCESS_ERROR, $offerSummaryController->javascriptAlertMessages[0]);
  1877. return self::getQuotation($codoffer);
  1878. */
  1879. }
  1880.  
  1881. /**
  1882. * Associa un servizio/sconto del concessionario all'offerta e ritorna un oggetto
  1883. * QuotationEntity aggiornato.
  1884. *
  1885. * doAction:add_extra -> addDealerDiscounts();
  1886. * /offer/offer_summary.php
  1887. *
  1888. * @param string $codoffer
  1889. * @param string $coddealerservice
  1890. */
  1891. public function setDealerService($codoffer, $coddealerservice, $value = 0, $modality = '')
  1892. {
  1893. // verifichiamo che l'offerta non sia completa
  1894. if ($this->offer->offerstate) {
  1895. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1896. }
  1897.  
  1898. $p_codLanguage = $this->tokenProperties['CODLANGUAGE'];
  1899. $idConcesionario = $_SESSION['CK_CONCESIONARIO']; // $p_codMarket.'_'.$p_codDealer.'_'.$p_dealerLocation; // -> $_SESSION['CK_CONCESIONARIO']
  1900.  
  1901. $descuentoConcesionario = new \DescuentoConcesionario();
  1902. $disc = $descuentoConcesionario->findByPrimaryKey($coddealerservice, $p_codLanguage);
  1903. $extraValue = !empty($disc) ? $disc->getCantidad() : '';
  1904. if (!empty($value) && !empty($disc) && $disc->getEditable() == 'Y')
  1905. $extraValue = $value;
  1906.  
  1907. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1908. $offerSummaryController = new \OfferSummaryController();
  1909.  
  1910. // forziamo gli attributi necessari all'azione
  1911. $offerSummaryController->doAction = 'add_extra'; // -> addExtraHandler
  1912.  
  1913. $offerSummaryController->extraType = 2; // -> addDealerDiscounts
  1914. $offerSummaryController->changeViewType = 1;
  1915. $offerSummaryController->viewType = $modality == 'detax' ? 1 : 0;
  1916. $offerSummaryController->isAPI = 1;
  1917. $offerSummaryController->extraCode = $coddealerservice;
  1918. $offerSummaryController->extraValue = str_replace("%", "", $extraValue);
  1919. $offerSummaryController->extraIsPercentage = strpos($extraValue, "%") === false ? 0 : 1;
  1920.  
  1921. $offerSummaryController->setProperties();
  1922. // attualizziamo l'offerta
  1923. $offerSummaryController->process();
  1924.  
  1925. if ($offerSummaryController->showJavascriptAlerts) {
  1926. return new BaseException(BaseException::PROCESS_ERROR,
  1927. $offerSummaryController->javascriptAlertMessages[0]);
  1928. }
  1929.  
  1930. return self::getQuotation($codoffer);
  1931. }
  1932.  
  1933. /**
  1934. * Elimina un servizio/sconto del concessionario all'offerta e ritorna un oggetto QuotationEntity aggiornato.
  1935. *
  1936. * doAction:add_extra -> removeExtraHandler();
  1937. * /offer/offer_summary.php
  1938. *
  1939. * @param string $codoffer
  1940. * @param string $coddealerservice
  1941. */
  1942. public function deleteDealerService($codoffer, $coddealerservice)
  1943. {
  1944. // verifichiamo che l'offerta non sia completa
  1945. if ($this->offer->offerstate) {
  1946. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1947. }
  1948.  
  1949. // carichiamo l'OfferSummaryController che usiamo come DAO...
  1950. $offerSummaryController = new \OfferSummaryController();
  1951.  
  1952. // forziamo gli attributi necessari all'azione
  1953. $offerSummaryController->doAction = 'remove_extra'; // -> removeExtraHandler
  1954.  
  1955. $offerSummaryController->extraType = 2; // -> removeDealerDiscounts
  1956. $offerSummaryController->changeViewType = 1;
  1957. $offerSummaryController->viewType = 1;
  1958. $offerSummaryController->isAPI = 1;
  1959. $offerSummaryController->extraCode = $coddealerservice;
  1960.  
  1961. $offerSummaryController->setProperties();
  1962. // attualizziamo l'offerta
  1963. $offerSummaryController->process();
  1964.  
  1965. if ($offerSummaryController->showJavascriptAlerts)
  1966. return new BaseException(BaseException::PROCESS_ERROR,
  1967. $offerSummaryController->javascriptAlertMessages[0]);
  1968.  
  1969. return self::getQuotation($codoffer);
  1970. }
  1971.  
  1972. /**
  1973. * Associa un servizio/sconto del concessionario con importo e descrizione libera
  1974. * all'offerta e ritorna un oggetto QuotationEntity aggiornato.
  1975. *
  1976. * E' necessario specificare la modalità di lavoro in cui avviene la richiesta
  1977. * (tax/detax) per determinare se il valore va
  1978. * considerato IVA compresa (tax) o IVA esclusa (detax).
  1979. * $value puo essere un float e rappresenta un valore assoluto, negativo se è uno sconto,
  1980. * positivo se è un servizio (costo) oppure una stringa che finisce con "%" per uno sconto
  1981. * percentuale, ad es. -10% oppure –6,5%, positivo se è un costo ad es. 10% oppure 5,5%
  1982. *
  1983. * @param string $codoffer
  1984. * @param string $coddealerservice
  1985. * @param string $value
  1986. * @param string $modality
  1987. * @param string $novaexcluded
  1988. */
  1989. public function setDealerFreeService($codoffer, $description, $value, $modality, $novaexcluded = 0, $discountfordealer = NULL)
  1990. {
  1991. // verifichiamo che l'offerta non sia completa
  1992. if ($this->offer->offerstate) {
  1993. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  1994. }
  1995.  
  1996. $value = str_replace(",", ".", $value);
  1997.  
  1998. // inizializzazione delle variabili d'ambiente
  1999. $this->initSession($codoffer);
  2000.  
  2001. // carichiamo l'OfferController che usiamo come DAO...
  2002. $offerController = new \OfferController();
  2003.  
  2004. $offerController->viewType = 0;
  2005. $offerController->changeViewType = 1;
  2006. $offerController->codoffer = $codoffer;
  2007.  
  2008. // attualizziamo l'offerta
  2009. $offerController->process(true);
  2010.  
  2011.  
  2012. // carichiamo l'OfferSummaryController che usiamo come DAO...
  2013. $offerSummaryController = new \OfferSummaryController();
  2014.  
  2015. // forziamo gli attributi necessari all'azione
  2016. $offerSummaryController->doAction = 'add_extra'; // -> addExtraHandler
  2017. $offerSummaryController->extraType = $novaexcluded != 1 ? 4 : 8; // -> addRealExtras
  2018. $offerSummaryController->changeViewType = 1;
  2019. $offerSummaryController->viewType = 0;
  2020. $offerSummaryController->discountfordealer = $discountfordealer;
  2021.  
  2022. if ($modality == 'detax') {
  2023. $offerSummaryController->viewType = 1;
  2024. if ($offerSummaryController->isAustria()) {
  2025. $offerSummaryController->novaextra = 1;
  2026. }
  2027. }
  2028.  
  2029. if ($offerSummaryController->isAustria()) {
  2030. $offerSummaryController->novaPercentage = $offerController->tplOffer['nova']; // valore della nova (es. 12% )
  2031. }
  2032.  
  2033. // novaextra
  2034. $offerSummaryController->isAPI = 1;
  2035. $offerSummaryController->extraCode = $description;
  2036. $offerSummaryController->extraValue = str_replace("%", "", $value);
  2037. $offerSummaryController->extraIsPercentage = strpos($value, "%") === false ? 0 : 1;
  2038.  
  2039. $offerSummaryController->setProperties();
  2040. // attualizziamo l'offerta
  2041. $offerSummaryController->process();
  2042.  
  2043. if ($offerSummaryController->showJavascriptAlerts) {
  2044. return new BaseException(BaseException::PROCESS_ERROR,
  2045. $offerSummaryController->javascriptAlertMessages[0]);
  2046. }
  2047.  
  2048. return self::getQuotation($codoffer);
  2049.  
  2050. }
  2051.  
  2052. /** deleteDealerFreeService
  2053. *
  2054. * @param string $codoffer
  2055. * @param string $coddealerservice
  2056. * @param string $novaexcluded
  2057. *
  2058. * @return QuotationEntity
  2059. */
  2060. public function deleteDealerFreeService($codoffer, $coddealerservice, $novaexcluded = 0)
  2061. {
  2062. // verifichiamo che l'offerta non sia completa
  2063. if ($this->offer->offerstate) {
  2064. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  2065. }
  2066.  
  2067. // carichiamo l'OfferSummaryController che usiamo come DAO...
  2068. $offerSummaryController = new \OfferSummaryController();
  2069.  
  2070. // forziamo gli attributi necessari all'azione
  2071. $offerSummaryController->doAction = 'remove_extra'; // -> removeExtraHandler
  2072.  
  2073. $offerSummaryController->extraType = $novaexcluded != 1 ? 4 : 8; // -> removeRealExtras
  2074. $offerSummaryController->changeViewType = 1;
  2075. $offerSummaryController->viewType = 1;
  2076. $offerSummaryController->isAPI = 1;
  2077. $offerSummaryController->extraCode = $coddealerservice;
  2078. $offerSummaryController->extraName = $coddealerservice;
  2079.  
  2080. $offerSummaryController->setProperties();
  2081. // attualizziamo l'offerta
  2082. $offerSummaryController->process();
  2083.  
  2084. if ($offerSummaryController->showJavascriptAlerts)
  2085. return new BaseException(BaseException::PROCESS_ERROR,
  2086. $offerSummaryController->javascriptAlertMessages[0]);
  2087.  
  2088. return self::getQuotation($codoffer);
  2089. }
  2090.  
  2091. /** setVehiclePrice
  2092. *
  2093. * @see
  2094. * /offer/view/offer_summary_detail_3103.tpl.php
  2095. *
  2096. * @param string $codoffer
  2097. * @param string $value
  2098. *
  2099. * @return \Application\Controller\BaseException|\iLinkQuotation\V2\Rest\Quotation\QuotationEntity
  2100. */
  2101. public function setVehiclePrice($codoffer, $value)
  2102. {
  2103. // verifichiamo che l'offerta non sia completa
  2104. if ($this->offer->offerstate) {
  2105. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  2106. }
  2107.  
  2108. $description = txt('Rabatt auf den Endpreis berechnet');
  2109. self::deleteDealerFreeService($codoffer, $description);
  2110.  
  2111. $sconto = self::calcDiscount($this->offer, $value);
  2112. $value = $sconto;
  2113.  
  2114.  
  2115. // inizializzazione delle variabili d'ambiente
  2116. $this->initSession($codoffer);
  2117.  
  2118. // carichiamo l'OfferController che usiamo come DAO...
  2119. $offerController = new \OfferController();
  2120.  
  2121. $offerController->viewType = 0;
  2122. $offerController->changeViewType = 1;
  2123. $offerController->codoffer = $codoffer;
  2124.  
  2125. // attualizziamo l'offerta
  2126. $offerController->process(true);
  2127.  
  2128.  
  2129. // $codoffer, $description, $value, $modality, $novaexcluded = 0
  2130. // lo sconto in Austria viene comunque applicato senza tasse
  2131. //return self::setDealerFreeService($codoffer, $description, $sconto, 'detax');
  2132.  
  2133. // diseguito troviamo l'implementazione ad-hoc della setDealerFreeService.
  2134.  
  2135. // carichiamo l'OfferSummaryController che usiamo come DAO...
  2136. $offerSummaryController = new \OfferSummaryController();
  2137.  
  2138. // forziamo gli attributi necessari all'azione
  2139. $offerSummaryController->doAction = 'add_extra'; // -> addExtraHandler
  2140.  
  2141. $offerSummaryController->extraType = $novaexcluded != 1 ? 4 : 8; // -> addRealExtras
  2142.  
  2143. $offerSummaryController->changeViewType = 1;
  2144.  
  2145. $offerSummaryController->viewType = 1;
  2146. if ($offerSummaryController->isAustria()) {
  2147. $offerSummaryController->novaextra = 1;
  2148. $offerSummaryController->novaPercentage = $offerController->tplOffer['nova']; // valore della nova (es. 12% )
  2149. }
  2150.  
  2151. // novaextra
  2152. $offerSummaryController->isAPI = 1;
  2153. $offerSummaryController->extraCode = $description;
  2154. $offerSummaryController->extraValue = str_replace("%", "", $value);
  2155. $offerSummaryController->extraIsPercentage = strpos($value, "%") === false ? 0 : 1;
  2156. //var_dump($offerSummaryController); die;
  2157. $offerSummaryController->setProperties();
  2158. // attualizziamo l'offerta
  2159. $offerSummaryController->process();
  2160.  
  2161. if ($offerSummaryController->showJavascriptAlerts) {
  2162. return new BaseException(BaseException::PROCESS_ERROR,
  2163. $offerSummaryController->javascriptAlertMessages[0]);
  2164. }
  2165.  
  2166. return self::getQuotation($codoffer);
  2167. }
  2168.  
  2169. /**
  2170. * Ritorna il valore dello sconto calcolato.
  2171. *
  2172. * FORMULA APPLICATA
  2173. * se p2 > PF (PF - (veh+opt) * (1+iva%))/(1+iva%)
  2174. * se p2 < PF -(((offertafinaleSoloIvato + (differ_base)) - PF) / ((1+iva%) + (nova%/100)))
  2175. *
  2176. * @see
  2177. * /offer/view/offer_summary_detail_3103.tpl.php
  2178. * /offer/js/discountedPrice.js
  2179. */
  2180. private function calcDiscount($offer, $value)
  2181. {
  2182. $quotation = self::getQuotation($offer->codoffer);
  2183. $tot_quotation_price = $quotation->tot_quotation_price->taxed_float;
  2184. $veh_price = $quotation->veh_price->detaxed_float;
  2185. $sconto = 0;
  2186.  
  2187. // inizializzazione delle variabili d'ambiente
  2188. $this->initSession($offer->codoffer);
  2189.  
  2190. // carichiamo l'OfferController che usiamo come DAO...
  2191. $offerController = new \OfferController();
  2192.  
  2193. $offerController->viewType = 0;
  2194. $offerController->changeViewType = 1;
  2195. $offerController->codoffer = $codoffer;
  2196.  
  2197. // attualizziamo l'offerta
  2198. $offerController->process(true);
  2199.  
  2200. $novaPerc = $offerController->tplOffer['nova']; // valore della nova (es. 12% )
  2201. $iva = $offerController->tplOffer['iva']; // iva di mercato
  2202. $d44 = $veh_price;
  2203.  
  2204. //var_dump($offerController->tplOffer); die;
  2205.  
  2206. //F66 prezzo finale (veh+opt)*iva
  2207. //tplOffer['total_pagare_ivato']
  2208. $prezzoOffertafinale = $tot_quotation_price; //tplOffer['total_pagare_ivato']
  2209. //D81 (PF)
  2210. //prezzo desiderato
  2211. $prezzofinale = $value;
  2212. //H83
  2213. //tplVehicle['taxedPrice_PC']+$this->tplOffer['optsoloivato']
  2214. $offertafinaleSoloIvato = $d44*(1+$iva); //this.offertafinaleSoloIvato;
  2215. //tplOffer['differbase']
  2216. $differ_base = -$offerController->tplOffer['differbase'];
  2217. //differbase diviso percentuale di nova
  2218. $prezzop1 = $differ_base/($novaPerc/100);
  2219.  
  2220. //Prezzo IVA incl. Attrezzatura speciale (senza NoVA Bonus & Discount)
  2221. //riferimento alla cella D44 del foglio excel allegato alla cr4871
  2222. //$d44 = $offertafinaleSoloIvato/(1+$iva);
  2223.  
  2224. //
  2225. $prezzop2 = ($d44-$prezzop1)*(1+$iva);
  2226. //se il prezzo inserito da campo è maggiore del prezzo dell'offerta
  2227. if ($prezzofinale > $prezzoOffertafinale) {
  2228. return new BaseException(BaseException::PROCESS_ERROR, txt('Not possible, desired price has to be lower then Listprice'));
  2229. } else {
  2230. $g_flagFormula = 0; //$this->isAustria() ? '0' : '1';
  2231. $viewType = 1; // 1 pagina di dettaglio, 0 pagina di summary.
  2232.  
  2233. $totExtraProduct=0;
  2234. /*
  2235. if ($offerController->viewType) {
  2236. $totExtraProduct = $offerController->tplOffer['extrasNovaTotal']['taxedPrice']+$offerController->tplOffer['extrasNoNovaTotal']['taxedPrice'];
  2237. } else {
  2238. $totExtraProduct = $offerController->tplOffer['extrasNoNovaTotal']['taxedPrice']+$offerController->tplOffer['extrasNovaTotal']['taxedPrice'];
  2239. }
  2240. */
  2241. // Oppure ciclo su tutti gli tmpSummaryExtra.
  2242. foreach ($offerController->tmpSummaryExtra as $extra) {
  2243. if ($extra['category'] == 4 && empty($extra['isextraopt'])) {
  2244. $totExtraProduct += $extra['taxedPrice'];
  2245. }
  2246. }
  2247. $totproduct = $totExtraProduct;
  2248.  
  2249. ///////////////////////////////attuazione della formula /////////////////////
  2250. if ($prezzop2 > $prezzofinale) {
  2251. //p2>PF
  2252. $sconto = ($prezzofinale - $offertafinaleSoloIvato-$totproduct)/(1+$iva);
  2253. } else {
  2254. if($g_flagFormula == 1) {
  2255. $sconto = -((($prezzoOffertafinale+$totproduct+($differ_base)) - $prezzofinale) / ((1+$iva)+($novaPerc/100)));
  2256. } else {
  2257. $sconto = -((($offertafinaleSoloIvato+$totproduct+($differ_base)) - $prezzofinale) / ((1+$iva)+($novaPerc/100)));
  2258. }
  2259. }
  2260.  
  2261. /////////////////////////fine attuazione ///////////////////////////////////
  2262. /*
  2263. * Quando si effettua l'inserimento del prezzo da videata summary (viewtype=0)
  2264. * si devono effetuare ulteriori considerazioni sullo sconto calcolato
  2265. * Se il differbase è maggiore di 0, allo sconto devo sorporare l'iva + la nova
  2266. * altrimenti solo l'iva
  2267. */
  2268. if ($viewType==0) {
  2269. if ($differ_base > 0) {
  2270. $sconto = $sconto*((1+$iva)+($novaPerc/100));
  2271. } else {
  2272. $sconto = $sconto*(1+$iva);
  2273. }
  2274. }
  2275. }
  2276.  
  2277. /*
  2278. $html = "prezzoOffertafinale: " . $prezzoOffertafinale . "\n";
  2279. $html .= "prezzo desiderato: " . $prezzofinale . "\n";
  2280. $html .= "offertafinaleSoloIvato: " . $offertafinaleSoloIvato . "\n";
  2281. $html .= "differ_base: -" . $differ_base . "\n";
  2282. $html .= "d44: " . $d44 . "\n";
  2283. $html .= "prezzop1: " . $prezzop1 . "\n";
  2284. $html .= "prezzop2: " . $prezzop2 . "\n";
  2285. $html .= "totproduct: " . $totproduct . "\n";
  2286. $html .= "sconto: " . $sconto . "\n";
  2287. var_dump($html); die;
  2288. */
  2289.  
  2290. return $sconto;
  2291. }
  2292.  
  2293. /**
  2294. * Rimuove una tassa dall'offerta (sul F/E viene disabilitata ma rimane visibile)
  2295. * e ritorna un oggetto QuotationEntity aggiornato.
  2296. *
  2297. * @param string $codoffer
  2298. * @param string $codtax
  2299. *
  2300. * @return QuotationEntity
  2301. */
  2302. public function deleteTax($codoffer, $codtax)
  2303. {
  2304.  
  2305. // verifichiamo che l'offerta non sia completa
  2306. if ($this->offer->offerstate) {
  2307. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  2308. }
  2309.  
  2310. $quotationEntity = self::getQuotation($codoffer);
  2311.  
  2312. $canbereset = false;
  2313. /**
  2314. * in reltà sembra che tutte le tasse possano essere azzerate
  2315. * questo ciclo serve a recuperare il codvalue che viene utilizzato
  2316. * dal controller
  2317. */
  2318. foreach ($quotationEntity->taxes as $tax) {
  2319. if ($tax->codtax == $codtax) {
  2320. $canbereset = $tax->canbereset;
  2321. // trick per superare indenni la setProperties del controller
  2322. // che utilizza nomi diversi delle variabili
  2323. $_POST['codtax'] = $tax->codvalue;
  2324. break; // trovata quella che ci serve è inutile continuare
  2325. }
  2326. }
  2327.  
  2328. if($_SESSION['SS_CODMARKET'] != "3239" && $codtax == "SCT") {
  2329. if (!$canbereset) {
  2330. return new BaseException(BaseException::PROCESS_ERROR,
  2331. "action deletetax: tax {$codtax} could not be removed!");
  2332. }
  2333. }
  2334.  
  2335. if($_SESSION['SS_CODMARKET'] == "3239") {
  2336.  
  2337. $result = -1;
  2338.  
  2339. if($codtax == "REGISTER_TAX") {
  2340. $result = \OfferBase::setRegTaxValue($codoffer, null); // REGTAXVGALUE
  2341. } else if($codtax == "MVT") {
  2342.  
  2343. $result = \OfferBase::setMvtValue($codoffer, 0);
  2344.  
  2345. // $result = \OfferBase::getMvtValue($codoffer); // MVT
  2346.  
  2347. /* if(count($result) > 0) {
  2348.  
  2349. if(is_null($result[0]['MVTVALUE'])) {
  2350. $result = \OfferBase::setMvtValue($codoffer, 0); // MVT
  2351. } else {
  2352. $result = \OfferBase::setMvtValue($codoffer, null); // MVT
  2353. }
  2354.  
  2355. } else {
  2356. $result = \OfferBase::setMvtValue($codoffer, 0); // MVT
  2357. }
  2358. */
  2359.  
  2360.  
  2361.  
  2362. } else if($codtax == "SCT") {
  2363. $result = \OfferBase::setSctValue($codoffer, null); // SCT
  2364. }
  2365.  
  2366. if ($result < 0) {
  2367. return new BaseException(BaseException::PROCESS_ERROR, "Edit error!");
  2368.  
  2369. }
  2370.  
  2371. return self::getQuotation($codoffer);
  2372.  
  2373. }
  2374.  
  2375. // carichiamo l'OfferSummaryController che usiamo come DAO...
  2376. $offerSummaryController = new \OfferSummaryController();
  2377.  
  2378. // forziamo gli attributi necessari alla action prima
  2379. // della setProperties perche alcuni sono utilizzati in tale contesto... :P
  2380. $offerSummaryController->changeViewType = 1;
  2381. $offerSummaryController->viewType = 1;
  2382. $offerSummaryController->isAPI = 1;
  2383. /**
  2384. * non ci siamo bevuti il cervello...
  2385. * in OfferSummaryController::taxHandler
  2386. * viene gestita una logica inversa per adattarsi al front-end html
  2387. */
  2388. $offerSummaryController->doAction = 'add_tax';
  2389. // $offerSummaryController->codTax = $codtax;
  2390.  
  2391. $offerSummaryController->setProperties();
  2392.  
  2393. // attualizziamo l'offerta
  2394. $offerSummaryController->process();
  2395.  
  2396. return self::getQuotation($codoffer);
  2397. }
  2398.  
  2399. public function getSincomByBrandMainDealer($p_codMarket, $p_codDealer, $codbrand)
  2400. {
  2401. $codmaindealer = \DealerBase::findByPrimaryKeyDealer($p_codMarket, $p_codDealer);
  2402. if ($codmaindealer) {
  2403. $codmaindealer = $codmaindealer[0]['CODMAINDEALER'];
  2404. } else {
  2405. $codmaindealer = $p_codDealer;
  2406. }
  2407.  
  2408. return \DealerBase::findByCodBrandCodMainDealer($codbrand, $codmaindealer, $p_codMarket);
  2409. }
  2410.  
  2411. /**
  2412. * Restituisce le regole di compatibilita dei prodotti.
  2413. *
  2414. * @param string $codoffer
  2415. * @param array $basket
  2416. * @param array $families
  2417. * @return \Application\Controller\BaseException
  2418. */
  2419. public function findCompatibleProducts($codoffer, $basket, $families)
  2420. {
  2421. $basketValues = explode(',', $basket);
  2422. $families = explode(',', $families);
  2423.  
  2424. if (empty($basketValues)) {
  2425. return new BaseException(BaseException::BAD_PARAMETERS, 'basket could not be empty!');
  2426. }
  2427.  
  2428. if (empty($families)) {
  2429. return new BaseException(BaseException::BAD_PARAMETERS, 'families could not be empty!');
  2430. }
  2431.  
  2432. require_once (APPL_PATH . 'COMMON/VinDriven/controllers/VinDrivenController.class.php');
  2433.  
  2434. $vinDrivenObj = new \VinDrivenController();
  2435. $vinDrivenObj->init();
  2436. $vinDrivenObj->isAPI = 1;
  2437.  
  2438. // Restituisce le regole di compatibilita dei prodotti.
  2439. $vinDrivenObj->setbasketRowsValues(json_encode($basketValues));
  2440. $vinDrivenObj->setfamilies(json_encode($families));
  2441. $vinDrivenObj->setplanSaleDate(\DateUtils::mysqlToUTC(date("Y-m-d H:i:s")));
  2442. $vinDrivenObj->setAction('findCompatibleProducts');
  2443. $productData = $vinDrivenObj->process();
  2444. var_dump($productData);
  2445. die();
  2446. }
  2447.  
  2448. /**
  2449. * Aggiunge uno o piu' elementi nel carrello e ritorna un oggetto QuotationEntity aggiornato.
  2450. *
  2451. * @param string $codoffer
  2452. * @param array $basket
  2453. * @param array $families
  2454. *
  2455. * @return QuotationEntity
  2456. */
  2457. public function storeBasketMVP($codoffer, $basket)
  2458. {
  2459. $offer = self::getOffer();
  2460. $basketValues = json_decode($basket);
  2461. // var_dump($offer); die;
  2462.  
  2463. $_SESSION['SS_APPLTYPE'] = 'PORTAL'; // necessario per il tool (newcontractproposal).
  2464.  
  2465. $mvs = $offer->getCodModel() . '' . $offer->getCodVersion() . '' . $offer->getCodSerie();
  2466.  
  2467. require_once (APPL_PATH . 'COMMON/VinDriven/controllers/VinDrivenController.class.php');
  2468.  
  2469. $vinDrivenObj = new \VinDrivenController();
  2470. $vinDrivenObj->init();
  2471. $vinDrivenObj->isAPI = 1;
  2472.  
  2473. $vinDrivenObj->setcodoffer($codoffer);
  2474.  
  2475. // vehicle
  2476. $vinDrivenObj->setmvs($mvs);
  2477. $vinDrivenObj->setAction('findByMVS');
  2478. $vehicleData = $vinDrivenObj->process();
  2479. // var_dump($vehicleData); die;
  2480.  
  2481. // listCustomerType
  2482. $vinDrivenObj->setAction('listCustomerType');
  2483. $listCustomerTypeData = $vinDrivenObj->process();
  2484.  
  2485. // listNations
  2486. $vinDrivenObj->setAction('listNations');
  2487. $listNationsData = $vinDrivenObj->process();
  2488.  
  2489. // contact
  2490. $vinDrivenObj->setcodcontact($offer->getCodContact());
  2491. $vinDrivenObj->setAction('findContactDetails');
  2492. $contactData = $vinDrivenObj->process();
  2493.  
  2494. $eligibilityData = array(
  2495. 'PLANSALEDATE' => \DateUtils::mysqlToUTC(date("Y-m-d H:i:s")), // '2016-11-11T00:00:00',
  2496. 'SALESTYPE' => 'DLR',
  2497. 'PLANTYPE' => 'A',
  2498. 'SOURCEOFSALE' => 'FGA',
  2499. 'hiddenCodOrigin' => ''
  2500. );
  2501.  
  2502. $vehicleData['WARRANTYCOVERAGECODE'] = 'W24';
  2503. $vehicleData['MVS'] = $vehicleData['CODMVS'];
  2504. $vehicleData['MVSdisplay'] = $vehicleData['CODMVS'];
  2505. $vehicleData['MODELYEARDISPLAY'] = $vehicleData['MODELYEAR'];
  2506. $vehicleData['MILEAGE'] = 0;
  2507. // var_dump($vehicleData); die;
  2508.  
  2509. // eliproduct
  2510. $sentdata = json_encode(
  2511. array(
  2512. 'vehicleData' => $vehicleData,
  2513. 'customerData' => $contactData,
  2514. 'eligibilityData' => $eligibilityData,
  2515. "OfferFlag" => ""
  2516. ));
  2517.  
  2518. $vinDrivenObj->setsentdata($sentdata);
  2519. $vinDrivenObj->setAction('eliproduct');
  2520. $eliproductData = $vinDrivenObj->process();
  2521. if (!empty($eliproductData['errorMessage'])) {
  2522. throw new BaseException(BaseException::PROCESS_ERROR,
  2523. "Mvp::listMvp: {$eliproductData['errorMessage']}");
  2524. }
  2525.  
  2526. $opts = array();
  2527. foreach ($eliproductData['opts'] as $opt) {
  2528. foreach ($basketValues as $basket) {
  2529. if (\Util::array_search_key_recursive($basket->familycode, $opt) &&
  2530. \Util::array_search_key_recursive($basket->plancode, $opt)) {
  2531. array_push($opts, $opt);
  2532. }
  2533. }
  2534. }
  2535.  
  2536. if (empty($opts)) {
  2537. return new BaseException(BaseException::BAD_PARAMETERS, 'basket could not be empty!');
  2538. }
  2539.  
  2540. // storeBasket
  2541. $sentdata = json_encode(
  2542. array(
  2543. 'basketRows' => $opts,
  2544. 'commonData' => array(
  2545. 'vehicleData' => $vehicleData,
  2546. 'customerData' => $contactData,
  2547. 'eligibilityData' => $eligibilityData,
  2548. 'OfferFlag' => '',
  2549. 'idBasket' => null,
  2550. 'codrepairorder' => ''
  2551. ),
  2552. 'basketInitData' => array(
  2553. "codoffer" => $codoffer,
  2554. "codorigin" => 3
  2555. )
  2556. ));
  2557.  
  2558. // storeBasket
  2559. $vinDrivenObj->setsentdata($sentdata);
  2560. $vinDrivenObj->setAction('storeBasket');
  2561. $basketData = $vinDrivenObj->process();
  2562. if (isset($basketData->results) && !empty($basketData->results->error)) {
  2563. throw new BaseException(BaseException::PROCESS_ERROR,
  2564. "Mvp::storeBasketMVP: {$basketData->results->error}");
  2565. }
  2566.  
  2567. // var_dump($basketData->results->idbasket); die;
  2568.  
  2569. return self::getQuotation($codoffer);
  2570. }
  2571.  
  2572. /**
  2573. * Funzione che cancella logicamente i dati del basket e ritorna un oggetto QuotationEntity aggiornato.
  2574. *
  2575. * @param string $codoffer
  2576. *
  2577. * @return QuotationEntity
  2578. */
  2579. public function deleteMvp($codoffer)
  2580. {
  2581. // verifichiamo che l'offerta non sia completa
  2582. if ($this->offer->offerstate) {
  2583. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  2584. }
  2585.  
  2586. require_once (APPL_PATH . 'COMMON/VinDriven/models/VinDrivenModel.class.php');
  2587.  
  2588. $basketEsalesData = \VinDrivenModel::findProductsByOffer($codoffer);
  2589. if (!empty($basketEsalesData) && intval($basketEsalesData[0]['IDBASKET'])) {
  2590. if (\VinDrivenModel::deleteAllBasket($basketEsalesData[0]['IDBASKET']) <= 0) {
  2591. return new BaseException(BaseException::PROCESS_ERROR,
  2592. "action deleteMvp: basketID {$basketEsalesData[0]['IDBASKET']} could not be removed!");
  2593. }
  2594. }
  2595.  
  2596. return self::getQuotation($codoffer);
  2597. }
  2598.  
  2599. /**
  2600. * API ResetAll
  2601. * dato in input un'offerta singola/multipla va a rimuovere tutti gli eventuali sconti, promozioni, accessori, tradeIn...
  2602. * Cancellazione di una singola offerta e di tutte le sue relazioni.
  2603. *
  2604. * Tecnicamente bisogna rimuovere i seguenti record:
  2605. * -offerta singola
  2606. * -offerproductdealerdiscount
  2607. * -offerproductextra
  2608. * -offerproductpromotion - OK
  2609. * -offeraccessory - OK
  2610. * -offerusedvehicle_new
  2611. * -scm_basket
  2612. *
  2613. * offerta multipla:
  2614. * -offerbasketextra
  2615. * -offerbasketoffers
  2616. *
  2617. * @param string $codoffer
  2618. *
  2619. * @return QuotationEntity
  2620. */
  2621. public function resetAll($codoffer)
  2622. {
  2623. self::initSession($codoffer);
  2624. $offer = self::getOffer();
  2625.  
  2626. // verifichiamo che l'offerta non sia completa
  2627. if ($offer->getOfferState()) {
  2628. return new BaseException(BaseException::PROCESS_ERROR, "Offer {$codoffer} is complete!");
  2629. }
  2630.  
  2631. $quot = self::getQuotation($codoffer);
  2632.  
  2633. if (!empty($quot->promotions)) { // 1. promotions
  2634. foreach ($quot->promotions as $promo) {
  2635. self::deletePromotion($codoffer, $promo->codpromotion);
  2636. }
  2637. }
  2638. if (!empty($quot->accessories)) { // 2. accessories
  2639. foreach ($quot->accessories as $acc) {
  2640. $onlywork=0;
  2641. self::deleteAccessory($codoffer, $acc->codaccessory, $onlywork);
  2642. }
  2643. }
  2644. /*
  2645. if (!empty($quot->taxes)) { // 3. taxes
  2646. foreach ($quot->taxes as $tax) {
  2647. if ($tax->codtax == 'IPT')
  2648. continue;
  2649.  
  2650. self::deleteTax($codoffer, $tax->codtax);
  2651. }
  2652. }
  2653. */
  2654. if (!empty($quot->services)) { // 3. sconti
  2655. foreach ($quot->services as $service) {
  2656. self::deleteDealerService($codoffer, $service->codservice);
  2657. }
  2658. }
  2659.  
  2660. //self::deleteDealerFreeService($codoffer, $coddealerservice, $novaexcluded = 0);
  2661.  
  2662. self::deleteTradeInValue($codoffer);
  2663.  
  2664. \OfferBase::cleanOffer($codoffer);
  2665. /*
  2666. if (intval(\OfferBase::removeOfferCascade($codoffer)) >= 0) {
  2667. return $quot;
  2668. }
  2669. */
  2670.  
  2671. return self::getQuotation($codoffer);
  2672. }
  2673.  
  2674. private function setOfferState($codoffer, $status = 0)
  2675. {
  2676. self::initSession($codoffer);
  2677. $offer = self::getOffer();
  2678.  
  2679. $offer->setOfferState(intval($status));
  2680. $offer->store();
  2681. }
  2682.  
  2683. /**
  2684. * createNegotiation
  2685. *
  2686. * @param string $codOffer
  2687. * @param string $codNegotiation
  2688. * @param string $nameNegotiation
  2689. */
  2690. private function createNegotiation($codOffer, $codNegotiation, $nameNegotiation)
  2691. {
  2692. $offer = self::getOffer();
  2693.  
  2694. $plannedDate = date('Y-m-d H:i:s', strtotime("+2 day"));
  2695. $codlead = ''; // !empty($this->getCodLead()) ? $this->getCodLead() : $_SESSION['CRM_CODLEAD'];
  2696.  
  2697. // Aggiorno il CRM WII CORE venendo dall'offerta
  2698. $wiiclass = new \crm_wii();
  2699. $result = $wiiclass->crmwiiCore(null, null, $_SESSION['SS_LOGINNAME'], 'OF',
  2700. $offer->getCodContact(), null, null, $plannedDate, $codNegotiation, $nameNegotiation,
  2701. null, null, null, null, null, null, $_SESSION["CK_SESION"], null,
  2702. $_SESSION['SS_CODBRAND'], $codlead);
  2703. // T9158
  2704. if ($result && $result == 1) {
  2705. // $result = $this->insertFollowUp($offer->getCodContact());
  2706. }
  2707.  
  2708. return $result;
  2709. }
  2710.  
  2711. /**
  2712. * getBreakPoints
  2713. *
  2714. * @see BreakPointsController /offerBreakPoints/index.php?action=load_break_point&
  2715. *
  2716. * @param string $codMarket
  2717. * @param string $codBrand
  2718. * @param string $codLanguage
  2719. * @return array
  2720. */
  2721. public function getBreakPoints($codMarket, $codBrand, $codLanguage)
  2722. {
  2723.  
  2724. $breakPointList = \MarketOfferBreakPoints::findbymarketbrand($codMarket, $codBrand,
  2725. $codLanguage);
  2726.  
  2727. foreach ($breakPointList as $k => $val) {
  2728. $breakPointList[$k]['SECTION_DESC'] = addslashes(
  2729. \Util::txtAPI($breakPointList[$k]['SECTION_TAG'], $this->tokenProperties));
  2730. }
  2731. return $breakPointList;
  2732. }
  2733.  
  2734. /**
  2735. * wrapper di DealerBase::findMainDealer che (inspiegabilmente)
  2736. * ritorna un array (anche vuoto!)
  2737. *
  2738. * @param string $codMarket
  2739. * @param string $coddealer
  2740. * @throws Exception
  2741. * @return string
  2742. */
  2743. private static function getCodMainDealer($codMarket, $coddealer)
  2744. {
  2745. $maindealer = \DealerBase::findMainDealer($coddealer, $codMarket);
  2746.  
  2747. if (isset($maindealer[0])) {
  2748. return $maindealer[0];
  2749. } else {
  2750. throw new \Exception("Invalid coddealer $codMarket/$coddealer");
  2751. }
  2752. }
  2753.  
  2754. static function isFlagshipVipOffer()
  2755. {
  2756. if (isset($_SESSION['SS_VIP_FLAGSHIP'])) {
  2757. return $_SESSION['SS_VIP_FLAGSHIP'];
  2758. }
  2759. return false;
  2760. }
  2761.  
  2762. static function checkDestinationIpt($codNation, $codRegion, $codDepartment)
  2763. {
  2764. $departments = \IPTBase::findByTechchar($codNation, $codRegion, 'DEST');
  2765. foreach ($departments as $idx => $val) {
  2766. if ($val['CODDEPARTMENT'] == $codDepartment) {
  2767. return true;
  2768. }
  2769. }
  2770.  
  2771. return false;
  2772. }
  2773.  
  2774. private static function isFlagshipDealer()
  2775. {
  2776. if (isset($_SESSION['SS_FLAGSHIP_DEALER'])) {
  2777. return $_SESSION['SS_FLAGSHIP_DEALER'];
  2778. }
  2779. return false;
  2780. }
  2781.  
  2782. private static function returnValidation($data)
  2783. {
  2784. switch ($data) {
  2785. case ('V'):
  2786. return 1;
  2787. case ('B'):
  2788. return 0;
  2789. case ('W'):
  2790. return 2;
  2791. }
  2792. }
  2793.  
  2794. private static function canDuplicateOffer()
  2795. {
  2796. return \MarketParams::findValueByPrimaryKey('OFFERMODIFY_ENABLED',
  2797. $_SESSION['SS_CODMARKET'], '', 0);
  2798. }
  2799.  
  2800. /**
  2801. * getPrivileges
  2802. * Ritorna una matrice con i privilegi dell'utente sull'applicazione.
  2803. * Al package viene sempre passato un array di ruoli, il ruolo
  2804. * primario per Link ed eventuali ruoli secondari per altre applicazioni
  2805. *
  2806. * @return array
  2807. */
  2808. private static function getPrivileges($codMarket, $roles)
  2809. {
  2810. $result = array();
  2811.  
  2812. $sql = 'pkLinkProfile.findPrivilegecodesByRole (:p_codMarket , :p_roles )';
  2813.  
  2814. $stmt = $GLOBALS['dbObj']->prepareCall($sql, true);
  2815. $stmt->setArrayParamDataTypes(array(
  2816. ':p_roles' => SQLT_CHR
  2817. ));
  2818. $stmt->execute(
  2819. array(
  2820. ':p_codMarket' => $codMarket,
  2821. ':p_roles' => $roles
  2822. ));
  2823.  
  2824. $data = $stmt->fetch();
  2825.  
  2826. unset($stmt);
  2827.  
  2828. foreach ($data as $loop)
  2829. $result[] = $loop['PRIVCODE'];
  2830.  
  2831. return $result;
  2832. }
  2833.  
  2834. private static function getCodLink($upsApplicationName, $codBrand)
  2835. {
  2836. $linkappls = \Profile::getLinkMarket($upsApplicationName);
  2837.  
  2838. if (!empty($linkappls)) {
  2839. foreach ($linkappls as $linkapp) {
  2840. if ($linkapp['CODBRAND'] == $codBrand)
  2841. return $linkapp['CODLINK'];
  2842. }
  2843. }
  2844.  
  2845. return 0;
  2846. }
  2847.  
  2848. private function getQrCodeFromConf ($configuration) {
  2849.  
  2850. /**
  2851. * Parametri mercato e lingua
  2852. */
  2853. $localeID = explode('_', $_SESSION['SS_LOCALE_ID']);
  2854. $languageConfigurator = $localeID[0];
  2855. $marketConfigurator = strtolower($localeID[1]);
  2856. $marketConf = $_SESSION['SS_CODMARKET'];
  2857. $languageConf = $_SESSION['SS_CODLANGUAGE'];
  2858.  
  2859. /**
  2860. * Parametro che permette di stabilire se
  2861. * allegare alla mail il codice QR (se restituito)
  2862. */
  2863. $attachQRinMail = false;
  2864.  
  2865. /**
  2866. * Si recupera il ccurl direttamente dal file
  2867. * di innesco per essere allineati a produzione.
  2868. *
  2869. * Se l'url non esiste il servizio non è previsto
  2870. * per quel mercato o quel brand.
  2871. */
  2872. $configuratorLoader = \CarConfB2C_Loader::getConfiguratorLoaderUrl($marketConf, $configuration['brandConf'], $languageConf);
  2873.  
  2874. if (!!$configuratorLoader) {
  2875. $confLoaderUrl = $configuratorLoader[0]['LOADERURL'];
  2876. $apiPostUrl = $configuratorLoader[0]['APIENDPOINTPOST'];
  2877. $apiQRUrl = $configuratorLoader[0]['APIENDPOINTQR'];
  2878. $brandDescription = strtolower($configuratorLoader[0]['BRANDNAME']);
  2879.  
  2880. $ch = curl_init();
  2881.  
  2882. curl_setopt($ch, CURLOPT_URL, $confLoaderUrl);
  2883. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2884. curl_setopt($ch, CURLOPT_HTTPHEADER, array());
  2885. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  2886.  
  2887. curl_setopt($ch, CURLOPT_PROXY, PROXY_HOST . ':' . PROXY_PORT);
  2888. curl_setopt($ch, CURLOPT_PROXYUSERPWD, PROXY_USER . ':' . PROXY_PASS);
  2889.  
  2890. $response = curl_exec($ch);
  2891.  
  2892. curl_close($ch);
  2893.  
  2894. $responseDecoded = json_decode($response, true)['models'][$configuration['metadataModel']];
  2895.  
  2896. if(!!$responseDecoded) {
  2897. $ccurl = $responseDecoded['url'].'/#/confID/';
  2898.  
  2899. /**
  2900. * Si apre il file con la configurazione XML vuota
  2901. */
  2902. $filename = APPL_PATH . 'apigility/data/file_config_empty.xml';
  2903. $xmlMod = simplexml_load_file($filename);
  2904.  
  2905. if ($xmlMod) {
  2906.  
  2907. //**************************************************************************
  2908.  
  2909. $metadataNode = $xmlMod->metadata;
  2910.  
  2911. /**
  2912. * Si modifica l'oggetto con l'xml con i dati provenienti
  2913. * dal percorso dell'offerta.
  2914. *
  2915. * ***************** METADATA NODE *****************
  2916. *
  2917. * 1) MARKET:
  2918. */
  2919. $metadataNode->Item[0] = (isset($marketConf)) ? $marketConf : '';
  2920.  
  2921. /**
  2922. * 2) BRAND:
  2923. */
  2924. $metadataNode->Item[1] = (isset($configuration['brandConf'])) ? $configuration['brandConf'] : '';
  2925.  
  2926. /**
  2927. * 3) LANGUAGE:
  2928. */
  2929. $metadataNode->Item[2] = (isset($languageConf)) ? $languageConf : '';
  2930.  
  2931. /**
  2932. * 4) MODEL DESCRIPTION:
  2933. */
  2934. $metadataNode->Item[3] = (isset($configuration['modelDescription'])) ? $configuration['modelDescription'] : '';
  2935.  
  2936. /**
  2937. * 5) CONFIGURATION DESCRIPTION:
  2938. */
  2939. $metadataNode->Item[4] = (isset($configuration['configDescription'])) ? $configuration['configDescription'] : '';
  2940.  
  2941. /**
  2942. * 6) MODEL NAME:
  2943. */
  2944. $metadataNode->Item[5] = (isset($configuration['modelName'])) ? $configuration['modelName'] : '';
  2945.  
  2946. /**
  2947. * 7) MODEL:
  2948. */
  2949. $metadataNode->Item[6] = (isset($configuration['metadataModel'])) ? $configuration['metadataModel'] : '';
  2950.  
  2951. /**
  2952. * 8) CCURL:
  2953. */
  2954. $metadataNode->Item[7] = (isset($ccurl)) ? $ccurl : '';
  2955.  
  2956. /**
  2957. * 9) FOOTER PRIVACY:
  2958. */
  2959. $metadataNode->Item[8] = (isset($configuration['footerPrivacy'])) ? $configuration['footerPrivacy'] : '';
  2960.  
  2961.  
  2962. $LMFINode = $xmlMod->LMFI;
  2963.  
  2964. /**
  2965. * ***************** LMFI NODE *****************
  2966. *
  2967. * 10) USE EXTENDED FILTERS:
  2968. */
  2969. $LMFINode->Item[0] = (isset($configuration['useExtdFilters'])) ? $configuration['useExtdFilters'] : '';
  2970.  
  2971. /**
  2972. * 11) SHOW MVS LIST:
  2973. */
  2974. $LMFINode->Item[1] = (isset($configuration['showMvsList'])) ? $configuration['showMvsList'] : '';
  2975.  
  2976. /**
  2977. * 12) USE LMFI PLUS:
  2978. */
  2979. $LMFINode->Item[2] = (isset($configuration['useLMFIPlus'])) ? $configuration['useLMFIPlus'] : '';
  2980.  
  2981. /**
  2982. * 13) PREDICTIVE GRIDS:
  2983. */
  2984. $LMFINode->Item[3] = (isset($configuration['predictiveGrids'])) ? $configuration['predictiveGrids'] : '';
  2985.  
  2986. /**
  2987. * 14) GROUPS:
  2988. * (e.g.: GROUP1|GROUP2|GROUP3)
  2989. */
  2990. $LMFINode->Item[4] = (isset($configuration['groups'])) ? $configuration['groups'] : '';
  2991.  
  2992. /**
  2993. * 15) MODEL:
  2994. */
  2995. $LMFINode->Item[5] = (isset($configuration['LMFIModel'])) ? $configuration['LMFIModel'] : '';
  2996.  
  2997. /**
  2998. * 16) MVS:
  2999. * (e.g.: 57609L204000)
  3000. */
  3001. $LMFINode->Item[6] = (isset($configuration['mvs'])) ? $configuration['mvs'] : '';
  3002.  
  3003. /**
  3004. * 17) DEVICE:
  3005. */
  3006. $LMFINode->Item[7] = (isset($configuration['device'])) ? $configuration['device'] : '';
  3007.  
  3008. /**
  3009. * 18) CO2:
  3010. */
  3011. $LMFINode->Item[8] = (isset($configuration['co2'])) ? $configuration['co2'] : '';
  3012.  
  3013. /**
  3014. * 19) BODY:
  3015. */
  3016. $LMFINode->Item[9] = (isset($configuration['body'])) ? $configuration['body'] : '';
  3017.  
  3018. /**
  3019. * 20) WHEL:
  3020. */
  3021. $LMFINode->Item[10] = (isset($configuration['whel'])) ? $configuration['whel'] : '';
  3022.  
  3023. /**
  3024. * 21) SEAT:
  3025. */
  3026. $LMFINode->Item[11] = (isset($configuration['seat'])) ? $configuration['seat'] : '';
  3027.  
  3028. /**
  3029. * 22) EQPM:
  3030. */
  3031. $LMFINode->Item[12] = (isset($configuration['eqpm'])) ? $configuration['eqpm'] : '';
  3032.  
  3033. /**
  3034. * 23) DRVE:
  3035. */
  3036. $LMFINode->Item[13] = (isset($configuration['drve'])) ? $configuration['drve'] : '';
  3037.  
  3038. /**
  3039. * 24) ENGN:
  3040. */
  3041. $LMFINode->Item[14] = (isset($configuration['engn'])) ? $configuration['engn'] : '';
  3042.  
  3043. /**
  3044. * 25) FUEL:
  3045. */
  3046. $LMFINode->Item[15] = (isset($configuration['fuel'])) ? $configuration['fuel'] : '';
  3047.  
  3048. /**
  3049. * 26) GEAR:
  3050. */
  3051. $LMFINode->Item[16] = (isset($configuration['gear'])) ? $configuration['gear'] : '';
  3052.  
  3053. /**
  3054. * 27) PACK:
  3055. */
  3056. $LMFINode->Item[17] = (isset($configuration['pack'])) ? $configuration['pack'] : '';
  3057.  
  3058. /**
  3059. * 28) OPTS:
  3060. * (e.g.: |009#-|011|023|025|026|112|132)
  3061. */
  3062. $LMFINode->Item[18] = (isset($configuration['opts'])) ? $configuration['opts'] : '';
  3063.  
  3064. /**
  3065. * 29) PRICE:
  3066. * (Il separatore è il punto)
  3067. */
  3068. $LMFINode->Item[19] = (isset($configuration['price'])) ? $configuration['price'] : '';
  3069.  
  3070. /**
  3071. * 30) PRICE NO VAT:
  3072. * (Il separatore è il punto)
  3073. */
  3074. $LMFINode->Item[20] = (isset($configuration['priceNoVat'])) ? $configuration['priceNoVat'] : '';
  3075.  
  3076. /**
  3077. * Nodo tools da considerare? Lasciare pre-compilato?
  3078. */
  3079. //$ToolsNode = $xmlMod->Tools;
  3080. //$firstImageUrl = $ToolsNode->groups[0]->group->images->image->layer['path'];
  3081. //$secondImageUrl = $ToolsNode->groups[1]->group->images->image->layer['path'];
  3082. //$thirdImageUrl = $ToolsNode->groups[2]->group->images->image->layer['path'];
  3083. //$baseUrl = $ToolsNode->groups[0]->group->settings->baseUrl;
  3084.  
  3085. /**
  3086. * Si memorizza il file xml opportunamente
  3087. * modificato nella variabile $xml e passato
  3088. * al payload
  3089. */
  3090. $xml = $xmlMod->asXML();
  3091.  
  3092. //**************************************************************************
  3093.  
  3094. $payloadArray = array(
  3095. "market" => $marketConfigurator,
  3096. "language" => $languageConfigurator,
  3097. "brand" => $brandDescription,
  3098. "configurationType" => "ANONYMOUS",
  3099. "configurationId" =>null,
  3100. "configurationData" => $xml
  3101. );
  3102.  
  3103. $payload = json_encode($payloadArray);
  3104.  
  3105. $headers = array(
  3106. 'Content-type: application/json',
  3107. 'Connection: close',
  3108. 'accept-encoding: gzip, deflate, br'
  3109. );
  3110.  
  3111. /**
  3112. * Inizializzo curl e le sue proprietà
  3113. */
  3114. $ch = curl_init();
  3115.  
  3116. /**
  3117. * Recupero il configuration ID da:
  3118. * bp_vl/bm/vehicles/configuration/post/set/json
  3119. */
  3120. curl_setopt($ch, CURLOPT_URL, $apiPostUrl);
  3121. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  3122. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  3123. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  3124. curl_setopt($ch, CURLOPT_POST, true);
  3125. curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
  3126. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  3127.  
  3128. curl_setopt($ch, CURLOPT_PROXY, PROXY_HOST . ':' . PROXY_PORT);
  3129. curl_setopt($ch, CURLOPT_PROXYUSERPWD, PROXY_USER . ':' . PROXY_PASS);
  3130.  
  3131. /**
  3132. * Eseguo la chiamata
  3133. */
  3134. $response = curl_exec($ch);
  3135.  
  3136. curl_close($ch);
  3137.  
  3138. $result = json_decode($response, true);
  3139.  
  3140. $configurationIdAlias = $result['configurationIdAlias'];
  3141.  
  3142. /**
  3143. * Check configuration ID:
  3144. *
  3145. * http://carconfigurator.fiat.com/ProductCatalog.asmx?op=getConfiguration
  3146. */
  3147. if (!!$configurationIdAlias || !curl_error($ch)) {
  3148.  
  3149. $configurationId = $result['configurationId'];
  3150.  
  3151. /**
  3152. * Si recupera il baseUrl direttamente dal file
  3153. * di innesco per essere allineati a produzione.
  3154. */
  3155. $ch = curl_init();
  3156.  
  3157. $baseUrl = urlencode($ccurl);
  3158.  
  3159. $url = $apiQRUrl;
  3160. $url .= '?market='.$languageConfigurator;
  3161. $url .= '&brand='.$brandDescription;
  3162. $url .= '&baseURL='.$baseUrl.$configurationIdAlias;
  3163. $url .= '&configurationId=?';
  3164. $url .= '&filters=';
  3165.  
  3166. curl_setopt($ch, CURLOPT_URL, $url);
  3167. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  3168. curl_setopt($ch, CURLOPT_HTTPHEADER, array());
  3169. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  3170.  
  3171. curl_setopt($ch, CURLOPT_PROXY, PROXY_HOST . ':' . PROXY_PORT);
  3172. curl_setopt($ch, CURLOPT_PROXYUSERPWD, PROXY_USER . ':' . PROXY_PASS);
  3173.  
  3174. $response = curl_exec($ch);
  3175.  
  3176. curl_close($ch);
  3177.  
  3178. $result = json_decode($response, true);
  3179.  
  3180. $qrcode = $result['Items'][0]['value'];
  3181.  
  3182. if (!!$qrcode) {
  3183. $attachQRinMail = true;
  3184. echo ('CONFIGURATION CODE: '.$configurationIdAlias).'<br>';
  3185. echo "<img src=data:image/png;base64,$qrcode>";
  3186. } else {
  3187. var_dump('QRcode is NULL'); exit();
  3188. }
  3189. } else {
  3190. var_dump('Configuration id Alias is NULL'); exit();
  3191. }
  3192. } else {
  3193. var_dump('Impossible to open the XML File'); exit();
  3194. }
  3195. } else {
  3196. var_dump('No configuration loader found'); exit();
  3197. }
  3198. } else {
  3199. var_dump('Service not allowed for current Market'); exit();
  3200. }
  3201. exit();
  3202. }
  3203. }
Add Comment
Please, Sign In to add comment