Guest User

Untitled

a guest
Feb 3rd, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 213.58 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by IntelliJ IDEA.
  4. * User: Lux
  5. * Date: 16/07/12
  6. * Time: 16.04
  7. * To change this template use File | Settings | File Templates.
  8. */
  9.  
  10. require_once 'Common/BaseService.php';
  11. require_once 'Account/Service.php';
  12. require_once 'Fototaxi/ExternalService.php';
  13. require_once 'Fototaxi/UtilsService.php';
  14.  
  15. require_once 'dto/fototaxi/GetAllArticoliResponse.php';
  16. require_once 'dto/fototaxi/GetCliserResponse.php';
  17. require_once 'dto/fototaxi/GetCliser2Response.php';
  18. require_once 'dto/fototaxi/GetUtenteFotografoResponse.php';
  19. require_once 'dto/fototaxi/GetUtenteResponse.php';
  20. require_once 'dto/fototaxi/GetTemaResponse.php';
  21. require_once 'dto/fototaxi/GetCliserPacchettoResponse.php';
  22.  
  23. require_once 'Batch/PagamentiUnicredit.php';
  24.  
  25. require_once APPLICATION_PATH . '/models/dto/account/UserItem.php';
  26.  
  27. class Fototaxi_OldService extends Common_BaseService
  28. {
  29. // Home ftp - serve a getXmlServizi
  30. const FTP_HOME = '/var/labo/home';
  31.  
  32. const LOGIN_STATUS_OK = 0;
  33.  
  34. // Mappatura costanti tornate dai servizi esterni - uguali alla classe ExternalService
  35. const LOGIN_STATUS_USER_NOT_FOUND = 30;
  36. const LOGIN_STATUS_USER_NOT_ACTIVE = 31;
  37. const LOGIN_STATUS_USER_WRONG_PASS = 32;
  38. const LOGIN_STATUS_USER_WRONG_USER = 33;
  39. const EXTERNAL_LOGIN_DISABLED_VIRTUAL_SHOP = 40;
  40.  
  41. /**
  42. * Per i test - configurazione cartella ftp-home con un percorso accessibile al filesystem della macchina che
  43. * lancia i test
  44. * @var string
  45. */
  46. public $alternativeFtpHome;
  47.  
  48. public function __construct()
  49. {
  50. parent::__construct();
  51. }
  52.  
  53. /**
  54. * @param struct|array $params
  55. * @return struct|array
  56. */ //@return GetAllArticoliResponse
  57. public function getAllArticoli($params)
  58. {
  59. $time_start = microtime(true); /*START TIME LOG*/
  60. $output = new GetAllArticoliResponse();
  61.  
  62. $codPortale = array_key_exists('codPortale', $params) ? (string)$params['codPortale'] : null;
  63. $username = array_key_exists('username', $params) ? (string)$params['username'] : null;
  64. $password = array_key_exists('password', $params) ? (string)$params['password'] : null;
  65.  
  66. // Login
  67. $loginStatus = $this->login($codPortale, $username, $password, false);
  68. if ($loginStatus != self::LOGIN_STATUS_OK) {
  69. $output->setStatusMessage(GetAllArticoliResponse::STATUS_USER_NOT_FOUND, array($codPortale, $username, $password));
  70. $strout = $output->__toString();
  71. $md5 = md5(Zend_Json::encode($strout));
  72. $strout = base64_encode(gzcompress(Zend_Json::encode($strout)));
  73. return array('md5' => $md5, 'data' => $strout);
  74. }
  75.  
  76. try {
  77. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  78. $utente = UtentiQuery::create()->filterByCodportale($codPortale)->filterByUsername($username)->findOne($con);
  79.  
  80. //------
  81. // GESTIONE CONVERSIONI
  82.  
  83. if (empty($utente)) {
  84. $utente = UtentiQuery::create()->filterByCodportaleold($codPortale)->filterByUsername($username)->findOne($con);
  85. }
  86.  
  87. $codPortale = empty($utente) ? $codPortale : $utente->getCodportale();
  88. //------------------------------------------
  89.  
  90. $portale = PortaliQuery::create()->filterByCodportale($codPortale)->findOne($con);
  91. if (empty($portale)) {
  92. throw new Exception("Portale inesistente: $codPortale");
  93. }
  94.  
  95. if (($portale->getTipoportale() == 'D') || ($utente->getCodfotografo() == 0)) {
  96. $fotografo = FotografiQuery::create()->filterByCodportale($utente->getcodPortale())->filterByAbilitato(1)->findOne($con);
  97. } else {
  98. $fotografo = FotografiQuery::create()
  99. ->filterByCodportale($utente->getCodportale())
  100. ->filterByCodlaboratorio($utente->getCodlaboratorio())
  101. ->filterByCodfotografo($utente->getCodfotografo())
  102. ->findOne($con);
  103. }
  104.  
  105. if (empty($fotografo)) {
  106. throw new Exception("Fotografo non esistente per portale: " . $portale->getCodportale() . " laboratorio: "
  107. . $utente->getCodlaboratorio() . " fotografo: " . $utente->getCodfotografo());
  108. }
  109.  
  110. $codLaboratorio = (string)$utente->getCodlaboratorio();
  111.  
  112. // RECUPERO DEI SERVIZI, SOLTANTO QUELLI ASSOCIATI AL LABORATORIO
  113. $servizi = ServiziQuery::create()
  114. ->filterByCodportale($portale->getCodportale())
  115. ->addJoinObject(new Join(array(ServiziPeer::CODPORTALE, ServiziPeer::CODSERVIZIO),
  116. array(ServizilaboratoriPeer::CODPORTALE, ServizilaboratoriPeer::CODSERVIZIO),
  117. Criteria::LEFT_JOIN))
  118. ->where(ServizilaboratoriPeer::CODLABORATORIO . " = '$codLaboratorio'")
  119. ->select(array('Fktiposervizio'))
  120. ->distinct()
  121. ->find($con)
  122. ->toArray();
  123. // SE NON CI SONO SERVIZI ASSOCIATI AL LABORATORIO SI CONSIDERA 'STAMPA FOTO' QUELLO DI DEFAULT
  124. if (count($servizi) == 0) {
  125. $servizi = array('SS');
  126. }
  127.  
  128. $queryArticoli = ArticoliQuery::create()
  129. ->filterByCodportale($portale->getCodportale())
  130. ->filterByCodlaboratorio($codLaboratorio)
  131. ->filterByVisualizzabile(array(1, 2, 3))
  132. ->filterByFlagtipoutente(array($utente->getTipo(), 'B'))
  133. ->filterByFktiposervizio($servizi);
  134.  
  135. $modalita = array_key_exists('modalita', $params) ? $params['modalita'] : null;
  136.  
  137. if (!($modalita === null) && (((int)$modalita) !== 0)) {
  138. // Modalità impostata
  139. $mod = (int)$modalita;
  140. $queryArticoli = $queryArticoli->filterByFlagmodalita(array(0, $mod));
  141. }
  142.  
  143. $this->logger->log(__FILE__, __LINE__, "QUERY GET ALL ARTICOLI: " . $queryArticoli->toString());
  144.  
  145. $articoliList = $queryArticoli->find($con);
  146.  
  147. if (count($articoliList) < 1) {
  148. throw new Exception("Articoli non Presenti per portale: $codPortale username: $username password: $password");
  149. }
  150.  
  151. // Listini
  152. $listiniFotografo = ListiniQuery::create()
  153. ->filterByCodportale($utente->getCodportale())
  154. ->filterByCodlaboratorio($utente->getCodlaboratorio())
  155. ->filterByCodlistino($fotografo->getCodpersonalizzato())
  156. ->filterByCodpersonalizzato('0')
  157. ->find($con);
  158.  
  159. $listiniLaboratorio = ListiniQuery::create()
  160. ->filterByCodportale($utente->getCodportale())
  161. ->filterByCodlaboratorio($utente->getCodlaboratorio())
  162. ->filterByCodlistino('0')
  163. ->filterByCodpersonalizzato('0')
  164. ->find($con);
  165.  
  166. $listiniPortale = ListiniQuery::create()
  167. ->filterByCodportale($utente->getCodportale())
  168. ->filterByCodlaboratorio('0')
  169. ->filterByCodlistino('0')
  170. ->filterByCodpersonalizzato('0')
  171. ->find($con);
  172.  
  173. // CAMPAGNE PROMOZIONALI - MAR 2012
  174. $now = new DateTime();
  175. $campagne = CampagneQuery::create()
  176. ->filterByCodiceportale($utente->getCodportale())
  177. ->filterByDatainizio(array('max' => $now))
  178. ->filterByDatafine(array('min' => $now))
  179. ->filterByTipo(array('ALL'), Criteria::IN)
  180. ->addJoin(array(CampagnePeer::CODICEPORTALE, CampagnePeer::CODICEPROMOZIONE),
  181. array(PromozioniPeer::CODPORTALE, PromozioniPeer::CODPROMOZIONE), Criteria::LEFT_JOIN)
  182. ->where(PromozioniPeer::TIPOUTENTE . " IN ('B', '" . $utente->getTipo() . "')")
  183. ->find($con);
  184. $listiniCampagneMap = array();
  185.  
  186. foreach ($campagne as $campagna) {
  187. //$campagna = new Campagne();
  188. $escluso = EsclusionefotograficampagneQuery::create()
  189. ->filterByCodportale($utente->getCodportale())
  190. ->filterByCodlaboratorio($utente->getCodlaboratorio())
  191. ->filterByCodfotografo($utente->getCodfotografo())
  192. ->filterByCodcampagna(array($campagna->getCodicecampagna(), ''))
  193. ->findOne($con);
  194.  
  195. $promoCampagna = $campagna->getPromozione();
  196.  
  197. if (empty($escluso) &&
  198. !empty($promoCampagna) &&
  199. $promoCampagna->isApplicabileUtente($utente) &&
  200. $promoCampagna->getCheckTemi() == 0 &&
  201. $promoCampagna->isApplicabileClient('FOTOTAXIOLD') &&
  202. $promoCampagna->isApplicabileFotografo($utente)
  203. ) {
  204. // Fotografo non escluso, recupero listino promozionale
  205. $listiniCampagna = ListinipromozionaliQuery::create()
  206. ->filterByCodiceportale($campagna->getCodiceportale())
  207. ->filterByCodicepromozione($campagna->getCodicepromozione())
  208. ->find($con);
  209. foreach ($listiniCampagna as $listinoCampagna) {
  210. $listinoCampagnaMap = array();
  211. $listinoCampagnaMap['codPortale'] = $listinoCampagna->getCodiceportale();
  212. $listinoCampagnaMap['codPromozione'] = (string)$listinoCampagna->getCodicepromozione();
  213. $listinoCampagnaMap['codArticolo'] = $listinoCampagna->getCodicearticolo();
  214. $listinoCampagnaMap['prezzo1'] = ''. (float)$listinoCampagna->getPrezzo1();
  215. $listinoCampagnaMap['quantita1'] = ''. (int)$listinoCampagna->getQuantita1();
  216. $listinoCampagnaMap['prezzo2'] = ''. (float)$listinoCampagna->getPrezzo2();
  217. $listinoCampagnaMap['quantita2'] = ''. (int)$listinoCampagna->getQuantita2();
  218. $listinoCampagnaMap['prezzo3'] = ''. (float)$listinoCampagna->getPrezzo3();
  219. $listinoCampagnaMap['quantita3'] = ''. (int)$listinoCampagna->getQuantita3();
  220. $listinoCampagnaMap['prezzo4'] = ''. (float)$listinoCampagna->getPrezzo4();
  221. $listinoCampagnaMap['quantita4'] = ''. (int)$listinoCampagna->getQuantita4();
  222. $listinoCampagnaMap['prezzo5'] = ''. (float)$listinoCampagna->getPrezzo5();
  223. $listinoCampagnaMap['quantita5'] = ''. (int)$listinoCampagna->getQuantita5();
  224. $listinoCampagnaMap['dataIns'] = (string)$listinoCampagna->getDatains();
  225.  
  226. // Conversione ad una mappa listino promozionale adatta all'output servizi
  227. $listiniCampagneMap[$listinoCampagna->getCodicearticolo()] = $listinoCampagnaMap;
  228. }
  229. }
  230. }
  231.  
  232. // FINE CAMPAGNE PROMOZIONALI
  233.  
  234. $credits = $this->_getCredits($con, $portale, $utente);
  235. foreach ($credits as $credit) {
  236. $credit = $this->__toPromo($credit);
  237. if ($credit->getFlagtipopromozione() == 4) {
  238. $listiniPrezzoFisso = ListinipromozionaliQuery::create()
  239. ->filterByCodiceportale($credit->getCodportale())
  240. ->filterByCodicepromozione($credit->getCodpromozione())
  241. ->find($con);
  242. foreach ($listiniPrezzoFisso as $listinoPrezzoFisso) {
  243. $listinoPrezzoFissoMap = array();
  244. $listinoPrezzoFissoMap['codPortale'] = $listinoPrezzoFisso->getCodiceportale();
  245. $listinoPrezzoFissoMap['codPromozione'] = (string)$listinoPrezzoFisso->getCodicepromozione();
  246. $listinoPrezzoFissoMap['codArticolo'] = $listinoPrezzoFisso->getCodicearticolo();
  247. $listinoPrezzoFissoMap['prezzo1'] = ''. (float)$listinoPrezzoFisso->getPrezzo1();
  248. $listinoPrezzoFissoMap['quantita1'] = ''. (int)$listinoPrezzoFisso->getQuantita1();
  249. $listinoPrezzoFissoMap['prezzo2'] = ''. (float)$listinoPrezzoFisso->getPrezzo2();
  250. $listinoPrezzoFissoMap['quantita2'] = ''. (int)$listinoPrezzoFisso->getQuantita2();
  251. $listinoPrezzoFissoMap['prezzo3'] = ''. (float)$listinoPrezzoFisso->getPrezzo3();
  252. $listinoPrezzoFissoMap['quantita3'] = ''. (int)$listinoPrezzoFisso->getQuantita3();
  253. $listinoPrezzoFissoMap['prezzo4'] = ''. (float)$listinoPrezzoFisso->getPrezzo4();
  254. $listinoPrezzoFissoMap['quantita4'] = ''. (int)$listinoPrezzoFisso->getQuantita4();
  255. $listinoPrezzoFissoMap['prezzo5'] = ''. (float)$listinoPrezzoFisso->getPrezzo5();
  256. $listinoPrezzoFissoMap['quantita5'] = ''. (int)$listinoPrezzoFisso->getQuantita5();
  257. $listinoPrezzoFissoMap['dataIns'] = (string)$listinoPrezzoFisso->getDatains();
  258.  
  259. $listiniCampagneMap[$listinoPrezzoFisso->getCodicearticolo()] = $listinoPrezzoFissoMap;
  260. }
  261. }
  262. }
  263.  
  264. $articoliServiziMap = array();
  265.  
  266. foreach ($articoliList as $articolo) {
  267. //$articolo = new Articoli();
  268. $articoloOut = new __Article();
  269.  
  270. // Creazione oggetto di output
  271. $articoloOut->setCodArticolo($articolo->getCodarticolo());
  272. $articoloOut->setCodPortale($articolo->getCodportale());
  273. $articoloOut->setCodLaboratorio($articolo->getCodlaboratorio());
  274. $articoloOut->setCodArticoloLabo('' . (int)$articolo->getCodarticololabo());
  275.  
  276. $codLayoutLabo = (string)$articolo->getCodlayoutlabo();
  277. $articoloOut->setCodLayoutLabo($codLayoutLabo);
  278. $articoloOut->setDesArticolo($articolo->getDesarticolo());
  279. $articoloOut->setUrlLogo((string)$articolo->getUrllogo());
  280. $articoloOut->setVisualizzabile((string)$articolo->getVisualizzabile());
  281. $articoloOut->setQualityHighSize((string)$articolo->getQualityhighsize());
  282. $articoloOut->setQualityMediumSize((string)$articolo->getQualitymediumsize());
  283. $articoloOut->setQualityLowSize((string)$articolo->getQualitylowsize());
  284. $articoloOut->setArticoloCorrelato1((string)$articolo->getArticolocorrelato1());
  285. $articoloOut->setArticoloCorrelato2((string)$articolo->getArticolocorrelato2());
  286. $articoloOut->setArticoloCorrelato3((string)$articolo->getArticolocorrelato3());
  287. $articoloOut->setPackaging((string)$articolo->getPackaging());
  288. $articoloOut->setAbilitato((string)$articolo->getAbilitato());
  289. $articoloOut->setInfoOrdine((string)$articolo->getInfoordine());
  290. $articoloOut->setRapporto(($articolo->getRapporto() == 0 ? "0.0" : ((string)$articolo->getRapporto())));
  291. $articoloOut->setCodPackaging((string)$articolo->getCodpackaging());
  292. $articoloOut->setGrammi((string)$articolo->getGrammi());
  293. $articoloOut->setIva((string)$articolo->getIva());
  294. $articoloOut->setQtMinimaOrdine((string)$articolo->getQtminimaordine());
  295. $articoloOut->setFlagArticoloComposito((string)$articolo->getFlagarticolocomposito());
  296. $articoloOut->setMaxTesto1((string)$articolo->getMaxtesto1());
  297. $articoloOut->setMaxTesto2((string)$articolo->getMaxtesto2());
  298.  
  299. $articoloOut->setClasse($articolo->getClasse());
  300. $articoloOut->setAltezza((string)$articolo->getAltezza());
  301.  
  302. // Per assemblatore
  303. $articoloOut->setMinPagine((string)$articolo->getMinpagine());
  304. $articoloOut->setMaxPagine((string)$articolo->getMaxpagine());
  305. $articoloOut->setCarta($articolo->getCarta());
  306. $articoloOut->setFormatoComposizione($articolo->getFormatocomposizione());
  307. $articoloOut->setModalita((string)$articolo->getFlagmodalita());
  308.  
  309. // Per baco assemblatore
  310. $articoloOut->setTipoServizio($articolo->getFktiposervizio());
  311. $articoloOut->setOrientamento($articolo->getOrientamento());
  312.  
  313. //*********************************
  314. // IMPOSTAZIONE ARTICOLO TRANSFERT
  315. //*********************************
  316. $articoloTransfert = null;
  317. $listinoTransfert = null;
  318. $legatoFotografo = $utente->getLegatofotografo();
  319. // Se non esiste un articolo transfert, la query viene tralasciata
  320. /* simo: modifica marzo 2015 - transfert differenziato utente finale /fotografo */
  321. $articoloTransfert = null;
  322. if ($utente->getTipo() == "F" && strlen(trim($articolo->getArticolocorrelato4())) > 0) {
  323.  
  324. $articoloTransfert = ArticoliQuery::create()
  325. ->filterByCodportale($articolo->getCodportale())
  326. ->filterByCodlaboratorio($articolo->getCodlaboratorio())
  327. ->filterByVisualizzabile(0)
  328. ->filterByCodarticolo($articolo->getArticolocorrelato4())
  329. ->findOne($con);
  330.  
  331. }
  332.  
  333. if ($articoloTransfert == null && strlen(trim($articolo->getArticolocorrelato1())) > 0) {
  334.  
  335. $articoloTransfert = ArticoliQuery::create()
  336. ->filterByCodportale($articolo->getCodportale())
  337. ->filterByCodlaboratorio($articolo->getCodlaboratorio())
  338. ->filterByVisualizzabile(0)
  339. ->filterByCodarticolo($articolo->getArticolocorrelato1())
  340. ->findOne($con);
  341.  
  342. }
  343. /* fine modifica simo */
  344. /*if(strlen(trim($articolo->getArticolocorrelato1())) > 0){
  345. $articoloTransfert = ArticoliQuery::create()
  346. ->filterByCodportale($articolo->getCodportale())
  347. ->filterByCodlaboratorio($articolo->getCodlaboratorio())
  348. ->filterByVisualizzabile(0)
  349. ->filterByCodarticolo($articolo->getArticolocorrelato1())
  350. ->findOne($con); */
  351.  
  352. if (!empty($articoloTransfert)) {
  353. // Listino personalizzato fotografo
  354. //if ($legatoFotografo == 1) {
  355. $applicaListinoFotografo = $utente->getCodportale() == "rikorda" ? ($utente->getFkruolo() == Account_Service::SHOP_ROLE) : ($legatoFotografo == 1);
  356. //if( $utente->getFkruolo() == Account_Service::SHOP_ROLE ){
  357. if( $applicaListinoFotografo ){
  358. $listinoTransfert = ListiniQuery::create()
  359. ->filterByCodarticolo($articoloTransfert->getCodarticolo())
  360. ->filterByCodportale($articoloTransfert->getCodportale())
  361. ->filterByCodlaboratorio($articoloTransfert->getCodlaboratorio())
  362. ->filterByCodlistino($fotografo->getCodpersonalizzato())
  363. ->filterByCodpersonalizzato(0)
  364. ->findOne($con);
  365. }
  366.  
  367. // Listino personalizzato laboratorio
  368. if (empty($listinoTransfert)) {
  369. $listinoTransfert = ListiniQuery::create()
  370. ->filterByCodarticolo($articoloTransfert->getCodarticolo())
  371. ->filterByCodportale($articoloTransfert->getCodportale())
  372. ->filterByCodlaboratorio($articoloTransfert->getCodlaboratorio())
  373. ->filterByCodlistino(0)
  374. ->filterByCodpersonalizzato(0)
  375. ->findOne($con);
  376. }
  377.  
  378. // Listino personalizzato portale
  379. if (empty($listinoTransfert)) {
  380. $listinoTransfert = ListiniQuery::create()
  381. ->filterByCodarticolo($articoloTransfert->getCodarticolo())
  382. ->filterByCodportale($articoloTransfert->getCodportale())
  383. ->filterByCodlaboratorio(0)
  384. ->filterByCodlistino(0)
  385. ->filterByCodpersonalizzato(0)
  386. ->findOne($con);
  387. }
  388.  
  389. }
  390.  
  391. //}
  392.  
  393. $articoloTransfertMap = array('desArticolo' => '', 'prezzo' => '0');
  394. if (!empty($articoloTransfert)) {
  395. $articoloTransfertMap['desArticolo'] = $articoloTransfert->getDesarticolo();
  396. $articoloTransfertMap['prezzo'] = empty($listinoTransfert) ? '0' : (string)$listinoTransfert->getPrezzo1();
  397. }
  398.  
  399. $articoloOut->setArticoloTransfert($articoloTransfertMap);
  400. //*************************************
  401. // IMPOSTAZIONE ARTICOLO TRANSFERT FINE
  402. //*************************************
  403.  
  404. // Calcolo listino
  405. $listino = null;
  406.  
  407. // Listino personalizzato fotografo
  408. //if (($utente->getLegatofotografo() == 1) && (count($listiniFotografo) > 0)) {
  409. $applicaListinoFotografo = $utente->getCodportale() == "rikorda" ? ($utente->getFkruolo() == Account_Service::SHOP_ROLE) : ($legatoFotografo == 1);
  410. if ($applicaListinoFotografo && (count($listiniFotografo) > 0)) {
  411. foreach ($listiniFotografo as $listinoFotografo) {
  412. if ($listinoFotografo->getCodarticolo() == $articolo->getCodarticolo()) {
  413. $listino = $listinoFotografo;
  414. break;
  415. }
  416. }
  417. }
  418.  
  419. // Listino laboratorio
  420. if (empty($listino) && (count($listiniLaboratorio) > 0)) {
  421. foreach ($listiniLaboratorio as $listinoLaboratorio) {
  422. if ($listinoLaboratorio->getCodarticolo() == $articolo->getCodarticolo()) {
  423. $listino = $listinoLaboratorio;
  424. break;
  425. }
  426. }
  427. }
  428.  
  429. // Listino portale
  430. if (empty($listino) && (count($listiniPortale) > 0)) {
  431. foreach ($listiniPortale as $listinoPortale) {
  432. if ($listinoPortale->getCodarticolo() == $articolo->getCodarticolo()) {
  433. $listino = $listinoPortale;
  434. break;
  435. }
  436. }
  437. }
  438.  
  439. // LISTINO NON TROVATO GENERA ERRORE
  440. if (empty($listino)) {
  441. throw new Exception("Listino non presente per portale: " . $utente->getCodportale() . " username: "
  442. . $utente->getUsername() . " password: " . $utente->getPassword()
  443. . " articolo: " . $articolo->getCodarticolo());
  444. }
  445. $listinoMap = array('codListino' => (string)$listino->getCodlistino(), 'codPortale' => $listino->getCodportale(),
  446. 'codLaboratorio' => (string)$listino->getCodlaboratorio(),
  447. 'codPersonalizzato' => (string)$listino->getCodpersonalizzato(), 'codArticolo' => (string)$listino->getCodarticolo(),
  448. 'prezzo1' => "" . (float)$listino->getPrezzo1(), 'quantita1' => "" . (int)$listino->getQuantita1(),
  449. 'prezzo2' => "" . (float)$listino->getPrezzo2(), 'quantita2' => "" . (int)$listino->getQuantita2(),
  450. 'prezzo3' => "" . (float)$listino->getPrezzo3(), 'quantita3' => "" . (int)$listino->getQuantita3(),
  451. 'prezzo4' => "" . (float)$listino->getPrezzo4(), 'quantita4' => "" . (int)$listino->getQuantita4(),
  452. 'prezzo5' => "" . (float)$listino->getPrezzo5(), 'quantita5' => "" . (int)$listino->getQuantita5());
  453. $articoloOut->setListino($listinoMap);
  454.  
  455. // CAMPAGNE PROMOZIONALI - MAR 2012
  456. if (array_key_exists($articolo->getCodarticolo(), $listiniCampagneMap)) {
  457. $listinoPromozionale = $listiniCampagneMap[$articolo->getCodarticolo()];
  458. $articoloOut->setListinoPromozionale($listinoPromozionale);
  459. }
  460. // FINE CAMPAGNE PROMOZIONALI
  461.  
  462. if (!array_key_exists($articolo->getFktiposervizio(), $articoliServiziMap)) {
  463. $articoliMap = array($articolo->getCodarticolo() => $articoloOut->__toString());
  464. $articoliServiziMap[$articolo->getFktiposervizio()] = $articoliMap;
  465. } else {
  466. $articoliMap = $articoliServiziMap[$articolo->getFktiposervizio()];
  467. $articoliMap[$articolo->getCodarticolo()] = $articoloOut->__toString();
  468. $articoliServiziMap[$articolo->getFktiposervizio()] = $articoliMap;
  469. }
  470.  
  471. }
  472. $output->setServicesArticles($articoliServiziMap);
  473. $output->setStatusMessage(GetAllArticoliResponse::STATUS_OK);
  474. } catch (Exception $e) {
  475. $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString());
  476. $output->setStatusMessage(GetAllArticoliResponse::STATUS_SERVER_ERROR, $e->getMessage());
  477. }
  478.  
  479. $this->logger->log(__FILE__, __LINE__, "Execution Time: " . (microtime(true) - $time_start) . " Sec", Zend_Log::DEBUG); /*STOP TIME LOG*/
  480.  
  481. // $strout = $output->__toString();
  482. // $strout = base64_encode(gzcompress(Zend_Json::encode($strout)));
  483.  
  484.  
  485. //controllo versione per client più vecchi di 1.5.11*, a loro $strout non va compresso
  486. $version = ClientversionQuery::create()->filterByCodportale($portale->getCodportale())->filterByUsername($username)->select("Version")->findOne($con);
  487. if (substr($version, 0, 5) === "1.5.9" || substr($version, 0, 6) === "1.5.10") {
  488. return $output->getServicesArticles();
  489. } else {
  490. $strout = utf8_decode($output->toXml());
  491. $md5 = md5($strout);
  492. $strout = base64_encode(gzcompress($strout));
  493. return array('md5' => $md5, 'data' => $strout);
  494. }
  495. }
  496.  
  497. /**
  498. * @param string $codPortale
  499. * @param string $codLaboratorio
  500. * @param string $codFotografo
  501. * @param string $username
  502. * @param string $password
  503. * @return GetUtenteFotografoResponse
  504. */
  505. public function getUtenteFotografo($codPortale, $codLaboratorio, $codFotografo, $username, $password)
  506. {
  507. $ret = new GetUtenteFotografoResponse();
  508.  
  509. $loginStatus = $this->login($codPortale, $username, $password, false);
  510.  
  511. // Login fallito
  512. if ($loginStatus != self::LOGIN_STATUS_OK) {
  513. $ret->setStatusMessage(GetUtenteFotografoResponse::STATUS_USER_NOT_FOUND, array($codPortale, $username, $password));
  514. return $ret;
  515. }
  516.  
  517. try {
  518. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  519.  
  520. $utente = UtentiQuery::create()->filterByCodportale($codPortale)->filterByUsername($username)->findOne($con);
  521. if (empty($utente)) {
  522. $utente = UtentiQuery::create()->filterByCodportaleold($codPortale)->filterByUsername($username)->findOne($con);
  523. }
  524.  
  525. $fotografo = UtentiQuery::create()
  526. ->filterByCodportale($utente->getCodportale())
  527. ->filterByCodlaboratorio($utente->getCodlaboratorio())
  528. ->filterByCodfotografo($utente->getCodfotografo())
  529. ->filterByTipo('F')
  530. ->findOne($con);
  531.  
  532. if (empty($fotografo)) {
  533. $ret->setStatusMessage(GetUtenteFotografoResponse::STATUS_FOTOGRAFO_NOT_FOUND,
  534. array($utente->getCodportale(), $utente->getCodlaboratorio(), $utente->getCodfotografo()));
  535. return $ret;
  536. }
  537.  
  538. $ret->setRagioneSociale($fotografo->getRagionesociale());
  539. $ret->setIndirizzo($fotografo->getIndirizzo());
  540. $ret->setCap($fotografo->getCap());
  541. $ret->setCitta($fotografo->getCitta());
  542. $ret->setProvincia($fotografo->getProvincia());
  543. $ret->setNazione($fotografo->getNazione());
  544. $ret->setStatusMessage(GetUtenteFotografoResponse::STATUS_OK);
  545. } catch (Exception $e) {
  546. $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
  547. $ret->setStatusMessage(GetUtenteFotografoResponse::STATUS_SERVER_ERROR, $e->getMessage());
  548. }
  549.  
  550. return $ret;
  551. }
  552.  
  553. /**
  554. * @throws Exception
  555. * @param string $codPortale
  556. * @param string $codLaboratorio
  557. * @param string $tipoUtente
  558. * @param string|int $modalita
  559. * @param string $codAgente
  560. * @param string $md5
  561. * @return string
  562. */
  563. public function getXmlServizi($codPortale, $codLaboratorio, $tipoUtente, $modalita, $codAgente = "", $md5 = "")
  564. {
  565.  
  566. $codLaboratorio = (int)$codLaboratorio;
  567. /*
  568. $tipoUtente = 'U';
  569. $modalita = 1;
  570. // I parametri sono dinamici, se sono 5 il terzo diventa il codice agente
  571. $params = func_get_args();
  572. $nParam = count($params);
  573. if($nParam > 4){
  574. $tipoUtente = $params[3];
  575. $modalita = (int) $params[4];
  576. }
  577. else{
  578. if($nParam > 2){
  579. $tipoUtente = $params[2];
  580. }
  581.  
  582. if($nParam > 3){
  583. $modalita = (int) $params[3];
  584. }
  585. }
  586. */
  587. $this->logger->log(__FILE__, __LINE__, "getXmlServizi PORTALE: $codPortale LABO: $codLaboratorio TIPO: $tipoUtente modalita: $modalita");
  588.  
  589. //-------------------------
  590. $ftpHome = empty($this->alternativeFtpHome) ? self::FTP_HOME : $this->alternativeFtpHome;
  591.  
  592. //-- TEST-LUX: solo per test serve per confrontare il file in cache generato del vecchio fototaxi con l'attuale
  593. $testFileContent = "";
  594.  
  595. $fileCacheName = "{$ftpHome}/cache/servizi_{$codPortale}_{$codLaboratorio}_{$tipoUtente}_{$modalita}";
  596. if (is_file($fileCacheName)) {
  597. $fileContent = file_get_contents($fileCacheName);
  598. if ($fileContent === FALSE) {
  599. $this->logger->log(__FILE__, __LINE__, "Error reading from $fileCacheName cache file", Zend_Log::ERR);
  600. } else {
  601. //-- TEST-LUX
  602. $testFileContent = $fileContent;
  603. //return $fileContent;
  604. }
  605. }
  606.  
  607. $xml = ''; // Output
  608.  
  609. //--------------------------
  610. // CONVERSIONE PORTALE
  611. //--------------------------
  612. try {
  613. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  614. $cp = ConversioneportaliQuery::create()
  615. ->filterByCodportaleold($codPortale)
  616. ->filterByCodlaboratorioold(0)
  617. ->filterByCodfotografoold(0)
  618. ->filterByCodgruppoold('')
  619. ->select(array('Codportaleold', 'Codportalenew'))
  620. ->findOne($con);
  621. if (!empty($cp)) {
  622. $this->logger->log(__FILE__, __LINE__, "CONVERSIONE -> Portale Vecchio: $codPortale Portale Nuovo: " . $cp['Codportalenew']);
  623. $codPortale = $cp['Codportalenew'];
  624. }
  625.  
  626. //-------------------------------
  627. // Lista servizi
  628. $ls = ServiziQuery::create()
  629. ->filterByCodportale($codPortale)
  630. ->filterByOrdinabilefototaxi('1')
  631. ->addJoinObject(new Join(array(ServiziPeer::CODPORTALE, ServiziPeer::CODSERVIZIO),
  632. array(ServizilaboratoriPeer::CODPORTALE, ServizilaboratoriPeer::CODSERVIZIO),
  633. Criteria::LEFT_JOIN))
  634. ->withColumn('ServiziLaboratori.Codlaboratorio', 'Codlaboratorio')
  635. ->where("ServiziLaboratori.CodLaboratorio = $codLaboratorio")
  636. ->find($con);
  637.  
  638. //-------------------------------
  639.  
  640. if ($ls->count() > 0) {
  641. $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
  642. $xml .= '<' . 'SERVICES' . '>';
  643.  
  644. $articoliQuery = ArticoliQuery::create()
  645. ->filterByCodportale($codPortale)
  646. ->filterByCodlaboratorio($codLaboratorio)
  647. ->condition('cond1', "Articoli.Flagtipoutente='B'")
  648. ->condition('cond2', 'Articoli.Flagtipoutente=?', $tipoUtente)
  649. ->where(array('cond1', 'cond2'), 'or');
  650.  
  651. /***********************************************************************************
  652. * ' per modalita mista devono essere scaricati tutti gli articoli
  653. * ' per tutte le altre devono essere scaricati articoli con flag=0 o flag=modalita
  654. ***********************************************************************************/
  655. if ($modalita == 1 || $modalita == 2) {
  656. $articoliQuery = $articoliQuery
  657. ->condition('cond3', 'Articoli.Flagmodalita=0')
  658. ->condition('cond4', 'Articoli.Flagmodalita=?', $modalita)
  659. ->where(array('cond3', 'cond4'), 'or');
  660.  
  661. }
  662.  
  663. $app = $articoliQuery->select(array('Codarticolo'))->find($con)->toArray();
  664.  
  665. $encThumb = '';
  666.  
  667. foreach ($ls as $service) {
  668. $service = $this->__toService($service);
  669.  
  670. //------------------------------------------------------------------------
  671. // SCRIVE NEL XML SOLO I SERVIZI PER I QUALI SONO STATI CARICATI ARTICOLI
  672. //-------------------------------------------------------------------------
  673. $haveArticoli = AlberoQuery::create()
  674. ->filterByCodportale($codPortale)
  675. ->where("SUBSTRING(Albero.Codalbero, 1, 2) = ?", $service->getCodservizio())
  676. ->where("( LENGTH(Albero.Codalbero=8) || LENGTH(Albero.Codalbero)=10 )")
  677. ->where('Albero.Codarticolo IN ?', $app)
  678. ->select(array('Codalbero'))->count($con);
  679.  
  680. //--------------------------------------
  681. if (($haveArticoli > 0) || ($service->getFktiposervizio() == 'SS')) {
  682. // Reperimento stream thumbnail
  683. $thumb = $service->getThumb();
  684. if (!empty($thumb)) {
  685. $thumb = stream_get_contents($service->getThumb());
  686. }
  687.  
  688.  
  689. // QUESTO IF SERVE SOLO IN AMBIENTE DI TEST, POICHE I DATASET XML POSSONO CONTENERE SOLO
  690. // STRINGHE BASE64
  691. // Conversione da base64 (solo in ambiente di Test)
  692. if (base64_encode(base64_decode($thumb)) === $thumb) {
  693. $thumb = base64_decode($thumb);
  694. }
  695.  
  696. if (strlen($thumb) > 0) {
  697. $encThumb = base64_encode($thumb);
  698. }
  699.  
  700. $xml .= '<SERVICE CODE="' . $service->getCodservizio() . '">';
  701. $xml .= '<TYPE>' . $service->getFktiposervizio() . '</TYPE>';
  702. $xml .= (strlen(trim($service->getTitolo())) > 0)
  703. ? '<TITLE><![CDATA[' . $service->getTitolo() . ']]></TITLE>'
  704. : '<TITLE/>';
  705. $xml .= (strlen(trim($service->getDescrizione())) > 0)
  706. ? '<DESCRIPTION><![CDATA[' . $service->getDescrizione() . ']]></DESCRIPTION>'
  707. : '<DESCRIPTION/>';
  708. $xml .= (strlen($thumb) > 0) ? '<THUMB>' . $encThumb . '</THUMB>' : '<THUMB/>';
  709. $xml .= '</SERVICE>';
  710.  
  711. }
  712. } // Fine foreach $ls as $service
  713.  
  714. $xml .= '</SERVICES>';
  715.  
  716. } // FINE if $ls->count() > 0
  717.  
  718.  
  719. //-- TEST-LUX: commentare
  720. if (!empty($testFileContent) && strcmp($xml, $testFileContent) !== 0) {
  721. $this->logger->log(__FILE__, __LINE__, "ERRORE getXmlServizi differenza con file di cache: $codPortale - $codLaboratorio - $tipoUtente - $modalita - $codAgente - $md5", Zend_Log::DEBUG);
  722. }
  723.  
  724. /* TEST-LUX: scommentare
  725. // Creazione cache
  726. $cached = file_put_contents($fileCacheName, $xml, LOCK_EX);
  727. if($cached === false){
  728. $this->logger->log(__FILE__, __LINE__, "Scrittura su cache file $fileCacheName fallita", Zend_Log::ERR);
  729. }
  730. */
  731.  
  732. $serverMd5 = md5(utf8_decode($xml));
  733.  
  734. $this->logger->log(__FILE__, __LINE__, "SERVIZI -> MD5 server: $serverMd5 MD5Client $md5", Zend_Log::INFO);
  735.  
  736. if ($md5 == $serverMd5) {
  737.  
  738. $xml = "";
  739. }
  740.  
  741. } catch (Exception $e) {
  742. $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
  743. throw $e;
  744. }
  745.  
  746. return $xml;
  747. }
  748.  
  749. /**
  750. * @param string $codPortale
  751. * @param string $username
  752. * @param string $password
  753. * @param bool $clientCall
  754. * @return int lo status della login (OK=0)
  755. */
  756. public function login($codPortale, $username, $password, $clientCall = true)
  757. {
  758. $status = self::LOGIN_STATUS_USER_NOT_FOUND;
  759.  
  760. if (in_array($codPortale, ExternalService::$externalPortals) && $clientCall) {
  761. try {
  762. $status = ExternalService::logIn($codPortale, $username, $password);
  763. if ($status != ExternalService::EXTERNAL_LOGIN_OK) {
  764. // Autenticazione fallita, codice di errore specifico
  765. return $status;
  766. }
  767. } catch (Exception $e) {
  768. $this->logger->log(__FILE__, __LINE__, "Errore autenticazione esterna: " . $e->getMessage());
  769. }
  770.  
  771. }
  772.  
  773. // Portale senza articoli
  774.  
  775.  
  776. // Autenticazione portale
  777. $accountService = new Account_Service();
  778. $utente = $accountService->loginPostali($codPortale, $username, $password, null, null, false, true);
  779. return $this->_accountServiceLoginStatusConvertion($utente);
  780.  
  781. }
  782.  
  783. /**
  784. * @throws Exception
  785. * @param $codPortale
  786. * @param $username
  787. * @param $password
  788. * @param bool $verifyLogin
  789. * @param bool $downloadNewPromotions
  790. * @return GetCliserResponse
  791. */
  792. public function getCliser($codPortale, $username, $password, $verifyLogin = true, $downloadNewPromotions = true)
  793. {
  794. $ret = new GetCliserResponse();
  795.  
  796. try {
  797. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_WRITE);
  798.  
  799. $utente = UtentiQuery::create()->filterBycodPortale($codPortale)->filterByUsername($username)->findOne($con);
  800.  
  801. // Gestione codportaleold
  802. if (empty($utente)) {
  803. $utente = UtentiQuery::create()->filterBycodPortaleOld($codPortale)->filterByUsername($username)->findOne($con);
  804. }
  805.  
  806. if (empty($utente)) {
  807. $this->logger->log(__FILE__, __LINE__, "Utente non trovat: codPortale=$codPortale, username=$username", Zend_Log::INFO);
  808. throw new Exception("Utente non trovato");
  809. }
  810.  
  811. // Fotografo, laboratorio, portale
  812. $fotografo = FotografiQuery::create()->filterByCodportale($utente->getcodPortale())
  813. ->filterBycodLaboratorio($utente->getcodLaboratorio())
  814. ->filterBycodFotografo($utente->getcodFotografo())
  815. ->findOne($con);
  816.  
  817. $laboratorio = LaboratoriQuery::create()->filterBycodPortale($utente->getcodPortale())
  818. ->filterBycodLaboratorio($utente->getcodLaboratorio())
  819. ->findOne($con);
  820.  
  821. $portale = PortaliQuery::create()->filterBycodPortale($utente->getcodPortale())->findOne($con);
  822.  
  823. // Dati anagrafici
  824. $ret->setTel($utente->getTel() == null ? "" : $utente->getTel());
  825. $ret->setCitta($utente->getCitta() == null ? "" : $utente->getCitta());
  826. $ret->setIndirizzo($utente->getIndirizzo() == null ? "" : $utente->getIndirizzo());
  827. $ret->setProvincia($utente->getProvincia() == null ? "" : $utente->getProvincia());
  828. $ret->setRagioneSociale($utente->getRagionesociale() == null ? "" : $utente->getRagionesociale());
  829. $ret->setNazione($utente->getNazione() == null ? "" : $utente->getNazione());
  830. $ret->setMail($utente->getMail() == null ? "" : $utente->getMail());
  831. $ret->setFax($utente->getFax() == null ? "" : $utente->getFax());
  832. $ret->setPiva($utente->getPiva() == null ? "" : $utente->getPiva());
  833. $ret->setCap($utente->getCap() == null ? "" : $utente->getCap());
  834.  
  835. // Inidirizzo sito e mailto
  836. if ($utente->getLegatofotografo() == 0) {
  837. $ret->setSitoWeb(strval($portale->getSitoweb()));
  838. $ret->setMailTo(strval($portale->getMail()));
  839. } else {
  840. $ret->setSitoWeb(strval($fotografo->getSitoweb()) == null ? "" : strval($fotografo->getSitoweb()));
  841. $ret->setMailTo(strval($fotografo->getMail()) == null ? "" : strval($fotografo->getMail()));
  842. }
  843.  
  844. // Dati ordini
  845. $ret->setCodFotografo(strval($utente->getcodFotografo()) == null ? "" : strval($utente->getcodFotografo()));
  846. $ret->setCodLabo(strval($utente->getcodLaboratorio()) == null ? "" : strval($utente->getcodLaboratorio()));
  847. $ret->setUsername(strval($utente->getUsername()) == null ? "" : strval($utente->getUsername()));
  848. $ret->setPassword(strval($utente->getPassword()) == null ? "" : strval($utente->getPassword()));
  849. $ret->setTipo(strval($utente->getTipo()) == null ? "" : strval($utente->getTipo()));
  850.  
  851. // Per fotografi, consegna sempre 'F'
  852. $ret->setConsegna(($utente->getTipo() == 'U') ? $utente->getConsegna() : 'F');
  853. $ret->setTipoPortale(strval($portale->getTipoportale()));
  854. $ret->setArtInProp(strval($laboratorio->getartInPropClient()));
  855. $ret->setMaxOrdine(strval(($utente->getmaxOrdineAutomatico() == 0) ? $fotografo->getmaxOrdineAutomatico() : $utente->getmaxOrdineAutomatico()));
  856.  
  857. // Fido residuo
  858. $accountService = new Account_Service();
  859. $ret->setFidoResiduo(strval($accountService->getFidoResiduo($utente->getIdutente())));
  860.  
  861. $ret->setPrimoOrdine(($utente->getHaveordini() == 0) ? '1' : '0');
  862. $ret->setPercScontoPrimoOrdine(strval($portale->getpercScontoPrimoOrdine()));
  863. $ret->setImpMinOrdine(strval($portale->getimpMinimoOrdine()));
  864. $ret->setQtaMinOrdine(strval($portale->getQtminimaordine()));
  865.  
  866. // Dati client
  867. $ret->setTimeNextDownload('0');
  868. $ret->setTimeNextDownloadNew(strval($portale->getAggclient()));
  869.  
  870. if (($laboratorio->getClientcompressionemin() == 0) || ($laboratorio->getClientcompressionemax() == 0)) {
  871. $ret->setMinQualitySpeed(strval($portale->getClientcompressionemin()));
  872. $ret->setMaxQualitySpeed(strval($portale->getClientcompressionemax()));
  873. } else {
  874. $ret->setMinQualitySpeed(strval($laboratorio->getClientcompressionemin()));
  875. $ret->setMaxQualitySpeed(strval($laboratorio->getClientcompressionemax()));
  876. }
  877.  
  878. $ret->setControlloFidoFotografo(strval($portale->getfotografoSoggettoFido()));
  879. $ret->setRifiutoAuto(strval($fotografo->getFlageliminaordini()));
  880. $ret->setCodPortale(strval($utente->getcodPortale()) == null ? "" : strval($utente->getcodPortale()));
  881.  
  882. // Cambiadestinazione e modalbrowser
  883. $cambia_destinazione = ($utente->getLegatofotografo() == 1 && (strlen($utente->getAmminfototaxi()) > 0 && $utente->getAmminfototaxi() === '0')) ? '0' : '1';
  884.  
  885. /* per fotoservice */
  886. if ($portale->gettipoPortale() == 'M' && strlen(trim(strval($utente->getcodGruppo()))) > 0) {
  887. $dg = DominigruppiQuery::create()->filterByCodportale($utente->getCodportale())->filterByCodgruppo($utente->getCodgruppo())->findOne($con);
  888. if (!empty($dg)) {
  889. $cambia_destinazione = $dg->getModalitapagamento() == 'M' ? '1' : '0';
  890. }
  891. }
  892. /* fine */
  893. /* modifica simo: postale rikorda non vede pulsante cambia destinazione */
  894. if ($portale->getCodportale() == "rikorda") {
  895. $cambia_destinazione = '0';
  896. }
  897. /* fine */
  898. $ret->setCambiaDestinazione($cambia_destinazione);
  899.  
  900. // TODO : filtro compressione skipped
  901.  
  902. $ret->setModalBrowser($portale->getModalbrowser() ? '1' : '0');
  903.  
  904. $promo_collegate = array();
  905.  
  906. //--------------------------------------------------
  907. $downloadCampagne = false;
  908.  
  909. $clientVersion = ClientversionQuery::create()->filterByCodportale($utente->getcodPortale())->filterByUsername($utente->getUsername())->findOne($con);
  910. if (!empty($clientVersion)) {
  911.  
  912. $paramVersion = explode(".", $clientVersion->getVersion());
  913.  
  914. $major = $paramVersion[0];
  915. $minor = $paramVersion[1];
  916. $build = $paramVersion[2];
  917.  
  918. if ($major == 1 && ($minor > 5 || ($minor == 5 && $build >= 109))) {
  919. $downloadCampagne = true;
  920. }
  921. }
  922.  
  923. $promozioni = array();
  924. if ($downloadCampagne) {
  925. // CAMPAGNE PROMOZIONALI - MARZO 2012
  926. $now = new DateTime();
  927. $campagne = CampagneQuery::create()
  928. ->filterByCodiceportale($utente->getCodportale())
  929. ->where("Campagne.Datainizio <= ?", $now)
  930. ->where("Campagne.Datafine >= ?", $now)
  931. ->where("Campagne.Tipo in ?", array('ALL'))
  932. ->find($con);
  933. if ($campagne->count() > 0) {
  934. foreach ($campagne as $campagna) {
  935. $escluso = EsclusionefotograficampagneQuery::create()
  936. ->filterByCodportale($utente->getcodPortale())
  937. ->filterByCodlaboratorio($utente->getCodlaboratorio())
  938. ->filterByCodfotografo($utente->getCodfotografo())
  939. ->where("Esclusionefotograficampagne.Codcampagna = ?",
  940. $campagna->getCodicecampagna())
  941. ->orWhere("EsclusioneFotografiCampagne.Codcampagna = ''")
  942. ->findOne($con);
  943.  
  944. /* esclusione di
  945. 1. campagne x tipo utente diverso da quello dell'utente finale
  946. 2. campagne con applicabilita per tema => solo online
  947. 3. campagne con applicabilita software != FOTOTAXIOLD
  948. */
  949. $promoCampagna = $campagna->getPromozione();
  950.  
  951. if (empty($escluso) &&
  952. !empty($promoCampagna) &&
  953. $promoCampagna->isApplicabileUtente($utente) &&
  954. $promoCampagna->getCheckTemi() == 0 &&
  955. $promoCampagna->isApplicabileClient('FOTOTAXIOLD') &&
  956. $promoCampagna->isApplicabileFotografo($utente)
  957. ) {
  958. $promozione = $promoCampagna->toArray();
  959. /*$promozione = PromozioniQuery::create()
  960. ->filterByCodportale($campagna->getCodiceportale())
  961. ->filterByCodpromozione($campagna->getCodicepromozione())
  962. ->findOne($con)->toArray();
  963.  
  964. $isApplicabileClient = $promozione["Checkclients"] == 0;
  965. if( $promozione["Checkclients"] == 1 ){
  966. $promozioneClients = PromozioniclientsQuery::create()
  967. ->filterByCodportale($campagna->getCodiceportale())
  968. ->filterByCodpromozione($campagna->getCodicepromozione())
  969. ->find($con);
  970. foreach($promozioneClients as $promozioneClient){
  971. if( $promozioneClient->getSoftware() == 'FOTOTAXIOLD'){
  972. $isApplicabileClient = true;
  973. break;
  974. }
  975. }
  976. }
  977.  
  978. $isApplicabileFotografo = true;
  979. if( $utente->getTipo() == 'F' && $promozione["Tipofotografo"] != 'all' && $promozione["Tipofotografo"] != $fotografo->getTipofotografo() ){
  980. $isApplicabileFotografo = false;
  981. }*/
  982.  
  983. /* esclusione di
  984. 1. campagne x tipo utente diverso da quello dell'utente finale
  985. 2. campagne con applicabilita per tema => solo online
  986. 3. campagne con applicabilita software != FOTOTAXIOLD
  987. */
  988. /*if ( ( $promozione["Tipoutente"] == 'B' || $promozione["Tipoutente"] == $utente->getTipo() ) &&
  989. $promozione["Checktemi"] == 0 && $isApplicabileClient && $isApplicabileFotografo) {*/
  990.  
  991. $promozione["QtaResidue"] = 0;
  992. $promozione["ValoreResiduo"] = 0;
  993.  
  994. /*$prom_obj= new __Promozioni();
  995. $prom_obj->setCod($promozione->getCodpromozione());
  996. $prom_obj->setDescrizione($promozione->getDescrizione());
  997. $prom_obj->setClasse($promozione->getclasseArticoli());
  998. $prom_obj->setPerc(strval($promozione->getPercsconto()));
  999. $prom_obj->setFlagTipoPromozione(strval($promozione->getFlagtipopromozione()));
  1000.  
  1001. // -----
  1002. $prom_obj->setQta('0');
  1003. $prom_obj->setValore('0');
  1004. // -----
  1005.  
  1006. $prom_obj->setImpMin(strval($promozione->getImpminimoordine()));
  1007. $prom_obj->setFlagPagaTransfert(strval($promozione->getPagatransfert()));
  1008. $prom_obj->setQtaApplicaSconto(strval($promozione->getQtaapplicasconto()));
  1009.  
  1010. $prom_obj->setArticoli($this->__jsonToString($promozione->getListaarticoli()));
  1011. $prom_obj->setQtaMin(strval($promozione->getQtaminimaordine()));
  1012. $prom_obj->setCondClassi($promozione->getCondclassearticoli());
  1013. $prom_obj->setCondArticoli($this->__jsonToString($promozione->getCondListaarticoli()));
  1014. $prom_obj->setCondRicorsiva(strval($promozione->getCondricorsiva()));
  1015. $prom_obj->setCodPromozioneCollegata($promozione->getCodpromozionecollegata());
  1016. $prom_obj->setProssimoOrdine(strval($promozione->getProssimoordine()));
  1017. $prom_obj->setQtaPromo(strval($promozione->getQta()));
  1018. $prom_obj->setPriorita(strval($promozione->getPriorita()));
  1019.  
  1020. if( $promozione->getCodpromozionecollegata() ){
  1021. $promo_collegate[] = $promozione->getCodpromozionecollegata();
  1022. }
  1023.  
  1024. //$ret->addPromozione($prom_obj);*/
  1025. $promozioni[] = $promozione;
  1026.  
  1027. //}
  1028.  
  1029. }
  1030. }
  1031. }
  1032. }
  1033. // @@since here tested
  1034.  
  1035. // Lista promozioni associate utente
  1036. $credits = $this->_getCredits($con, $portale, $utente);
  1037.  
  1038. // Log dei credits
  1039. $logCredits = "Credits: [";
  1040. $n = count($credits);
  1041. foreach ($credits as $i => $credit) {
  1042. $logCredits .= $credit;
  1043. if ($i < $n - 1) {
  1044. $logCredits .= ", ";
  1045. }
  1046.  
  1047. if (!$downloadNewPromotions &&
  1048. (($credit->getFlagtipopromozione() == 5 || $credit->getFlagtipopromozione() == 6) ||
  1049. ($credit->getCondlistaarticoli() != null && $credit->getCondlistaarticoli() != "") ||
  1050. ($credit->getCondclassearticoli() != null && $credit->getCondclassearticoli() != "") ||
  1051. ($credit->getListaarticoli() != null && $credit->getListaarticoli() != "") ||
  1052. $credit->getProssimoordine() != 0 || $credit->getQtaminimaordine() > 0 ||
  1053. ($credit->getCodpromozionecollegata() != null && $credit->getCodpromozionecollegata() != "")
  1054. )
  1055. ) {
  1056. continue;
  1057. }
  1058.  
  1059. $credit = $this->__toPromo($credit);
  1060. $promozione = $credit->toArray();
  1061. $promozione["QtaResidue"] = $credit->getQtaResidue();
  1062. $promozione["ValoreResiduo"] = $credit->getValoreResiduo();
  1063.  
  1064. /*$prom_obj= new __Promozioni();
  1065. $prom_obj->setCod($credit->getCodpromozione());
  1066. $prom_obj->setDescrizione($credit->getDescrizione());
  1067. $prom_obj->setClasse($credit->getClassearticoli());
  1068. $prom_obj->setPerc(strval($credit->getPercsconto()));
  1069. $prom_obj->setFlagTipoPromozione(strval($credit->getFlagtipopromozione()));
  1070. $prom_obj->setQta(strval($credit->getQtaResidue()));
  1071. $prom_obj->setValore(strval($credit->getValoreResiduo()));
  1072. $prom_obj->setImpMin(strval($credit->getImpminimoordine()));
  1073.  
  1074. //modifiche 02_2005------------------------------------------------------
  1075. $prom_obj->setFlagPagaTransfert(strval($credit->getPagatransfert()));
  1076. //-----------------------------------------------------------------------
  1077. $prom_obj->setQtaApplicaSconto(strval($credit->getQtaapplicasconto()));
  1078.  
  1079. $prom_obj->setArticoli($this->__jsonToString($credit->getListaarticoli()));
  1080. $prom_obj->setQtaMin(strval($credit->getQtaminimaordine()));
  1081. $prom_obj->setCondClassi($credit->getCondclassearticoli());
  1082. $prom_obj->setCondArticoli($this->__jsonToString($credit->getCondListaarticoli()));
  1083. $prom_obj->setCondRicorsiva(strval($credit->getCondricorsiva()));
  1084. $prom_obj->setCodPromozioneCollegata($credit->getCodpromozionecollegata());
  1085. $prom_obj->setProssimoOrdine(strval($credit->getProssimoordine()));
  1086. $prom_obj->setQtaPromo(strval($credit->getQta()));
  1087. $prom_obj->setPriorita(strval($credit->getPriorita()));
  1088. */
  1089. if ($credit->getCodpromozionecollegata()) {
  1090. $promo_collegate[] = $credit->getCodpromozionecollegata();
  1091. }
  1092.  
  1093. //$ret->addPromozione($prom_obj);
  1094. $promozioni[] = $promozione;
  1095.  
  1096. }
  1097. $logCredits .= "]";
  1098.  
  1099. $promozioni_tmp = array();
  1100. foreach ($promozioni as $promozione) {
  1101. $promozioni_tmp[] = $promozione["Priorita"];
  1102. }
  1103. array_multisort($promozioni_tmp, SORT_ASC, $promozioni);
  1104.  
  1105. foreach ($promozioni as $promozione) {
  1106.  
  1107. $prom_obj = new __Promozioni();
  1108. $prom_obj->setCod($promozione["Codpromozione"]);
  1109. $prom_obj->setDescrizione($promozione["Descrizione"]);
  1110. $prom_obj->setClasse($promozione["Classearticoli"]);
  1111. $prom_obj->setPerc(strval($promozione["Percsconto"]));
  1112. $prom_obj->setFlagTipoPromozione(strval($promozione["Flagtipopromozione"]));
  1113. $prom_obj->setQta(strval($promozione["QtaResidue"]));
  1114. $prom_obj->setValore(strval($promozione["ValoreResiduo"]));
  1115. $prom_obj->setImpMin(strval($promozione["Impminimoordine"]));
  1116.  
  1117. //modifiche 02_2005------------------------------------------------------
  1118. $prom_obj->setFlagPagaTransfert(strval($promozione["Pagatransfert"]));
  1119. //-----------------------------------------------------------------------
  1120. $prom_obj->setQtaApplicaSconto(strval($promozione["Qtaapplicasconto"]));
  1121.  
  1122. $prom_obj->setArticoli($this->__jsonToString($promozione["Listaarticoli"]));
  1123. $prom_obj->setQtaMin(strval($promozione["Qtaminimaordine"]));
  1124. $prom_obj->setCondClassi($promozione["Condclassearticoli"]);
  1125. $prom_obj->setCondArticoli($this->__jsonToString($promozione["Condlistaarticoli"]));
  1126. $prom_obj->setCondRicorsiva(strval($promozione["Condricorsiva"]));
  1127. $prom_obj->setCodPromozioneCollegata($promozione["Codpromozionecollegata"]);
  1128. $prom_obj->setProssimoOrdine(strval($promozione["Prossimoordine"]));
  1129. $prom_obj->setQtaPromo(strval($promozione["Qta"]));
  1130.  
  1131. $ret->addPromozione($prom_obj);
  1132.  
  1133. }
  1134.  
  1135. if (!empty($promo_collegate)) {
  1136.  
  1137. $collegate = PromozioniQuery::create()
  1138. ->filterByCodportale($portale->getCodportale())
  1139. ->filterByCodpromozione($promo_collegate, Criteria::IN)
  1140. ->find($con);
  1141.  
  1142. foreach ($collegate as $collegata) {
  1143.  
  1144. $prom_obj = new __Promozioni();
  1145. $prom_obj->setCod($collegata->getCodpromozione());
  1146. $prom_obj->setDescrizione($collegata->getDescrizione());
  1147. $prom_obj->setClasse($collegata->getClassearticoli() != "" ? $collegata->getClassearticoli() : "");
  1148. $prom_obj->setPerc(strval($collegata->getPercsconto()));
  1149. $prom_obj->setFlagTipoPromozione(strval($collegata->getFlagtipopromozione()));
  1150. $prom_obj->setQta(strval($collegata->getQta()));
  1151. $prom_obj->setValore(strval($collegata->getValore()));
  1152. $prom_obj->setImpMin(strval($collegata->getImpminimoordine()));
  1153.  
  1154. //modifiche 02_2005------------------------------------------------------
  1155. $prom_obj->setFlagPagaTransfert(strval($collegata->getPagatransfert()));
  1156. //-----------------------------------------------------------------------
  1157. $prom_obj->setQtaApplicaSconto(strval($collegata->getQtaapplicasconto()));
  1158.  
  1159. $prom_obj->setArticoli($this->__jsonToString($collegata->getListaArticoli()));
  1160. $prom_obj->setQtaMin(strval($collegata->getQtaminimaordine()));
  1161. $prom_obj->setCondClassi($collegata->getCondclassearticoli());
  1162. $prom_obj->setCondArticoli($this->__jsonToString($collegata->getCondListaArticoli()));
  1163. $prom_obj->setCondRicorsiva(strval($collegata->getCondricorsiva()));
  1164. $prom_obj->setCodPromozioneCollegata($collegata->getCodpromozionecollegata());
  1165.  
  1166. $ret->addPromozioneCollegata($prom_obj);
  1167.  
  1168. }
  1169.  
  1170.  
  1171. }
  1172.  
  1173. $this->logger->log(__FILE__, __LINE__, $logCredits);
  1174.  
  1175. // Dimensione immagini basse risoluzione
  1176. $config = Zend_Registry::get('Redarea_Configuration');
  1177. $ret->setLresMaxSize($config->image->web->max->size);
  1178.  
  1179. // Fototaxi-web
  1180. $ret->setFototaxiWeb($portale->getFototaxiweb() ? '1' : '0');
  1181.  
  1182. $ret->setStatusMessage(GetCliserResponse::STATUS_OK);
  1183.  
  1184.  
  1185. } catch (Exception $e) {
  1186. $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
  1187. $ret->setStatusMessage(GetCliserResponse::STATUS_SERVER_ERROR, array($e->getMessage()));
  1188. }
  1189.  
  1190.  
  1191. //D:\projects\rikorda_old\front\src\com\pytaxi\util\XmlRpcMethods.java, porting fino a linea
  1192.  
  1193. return $ret;
  1194. }
  1195.  
  1196. /**
  1197. * @param string $codPortale
  1198. * @param string $username
  1199. * @param string $password
  1200. * @param string $version
  1201. * @param string $release
  1202. * @return GetCliser2Response
  1203. */
  1204. public function getCliser2($codPortale, $username, $password, $version, $release = null)
  1205. {
  1206.  
  1207. $paramVersion = explode(".", $version);
  1208.  
  1209. $major = $paramVersion[0];
  1210. $minor = $paramVersion[1];
  1211. $build = $paramVersion[2];
  1212.  
  1213. $downloadNewPromotions = false;
  1214.  
  1215. // download nuove promozioni se versione fototaxi è >= 1.5.139
  1216. //if( $major == 1 && ($minor>5 || ($minor == 5 && $build >= 139)) ){
  1217. if ($major == 1 && ($minor > 5 || ($minor == 5 && $build >= 108))) {
  1218. $downloadNewPromotions = true;
  1219. }
  1220.  
  1221. $response = new GetCliser2Response();
  1222.  
  1223. try {
  1224.  
  1225. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_WRITE);
  1226.  
  1227. $sql = "REPLACE INTO ClientVersion (codPortale, username, version, rel) VALUES ('" . $codPortale . "', '" . $username . "', '" . $version . "', '" . $release . "')";
  1228. $stmt = $con->prepare($sql);
  1229. $stmt->execute();
  1230.  
  1231. } catch (Exception $e) {
  1232. $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
  1233. $response->setStatusMessage(GetCliser2Response::STATUS_SERVER_ERROR, array($e->getMessage()));
  1234. return $response;
  1235. }
  1236.  
  1237. //$ret = $this->getCliser($codPortale, $username, $password, true);
  1238. $ret = $this->getCliser($codPortale, $username, $password, true, $downloadNewPromotions);
  1239.  
  1240. $response->fromGetCliserRespoonse($ret);
  1241. $response->setUrlServerPhp('/services/xmlrpc.php');
  1242. $response->setPathUploadPhp('/services/upload_fototaxi.php');
  1243. $response->setStatusMessage($ret->getStatus());
  1244. //$response->setStatusMessage(!$downloadNewPromotions ? GetCliser2Response::STATUS_VERSION_UPG : $ret->getStatus());
  1245.  
  1246. return $response;
  1247.  
  1248. }
  1249.  
  1250. /**
  1251. * Torna una mappa di file solo se il codice md5 e' diverso
  1252. * @param struct|array $params - chiavi:
  1253. * codPortale
  1254. * codLaboratorio (usato solo se username e password sono null)
  1255. * codFotografo (usato solo se username e password sono null)
  1256. * username
  1257. * password
  1258. * md5Logo
  1259. * md5Banner
  1260. * md5Tema
  1261. * lang=it
  1262. * @return GetTemaResponse
  1263. */
  1264. public function getTema($params)
  1265. {
  1266. $ret = new GetTemaResponse();
  1267.  
  1268.  
  1269. //$TEMA = 'theme_' . (array_key_exists('lang', $params) ? $params['lang'] : 'it') . '.zip';
  1270.  
  1271. $codPortale = array_key_exists('codPortale', $params) ? (string)$params['codPortale'] : null;
  1272. $codLaboratorio = array_key_exists('codLaboratorio', $params) ? (string)$params['codLaboratorio'] : null;
  1273. $codFotografo = array_key_exists('codFotografo', $params) ? (string)$params['codFotografo'] : null;
  1274. $codGruppo = array_key_exists('codGruppo', $params) ? (string)$params['codGruppo'] : null;
  1275. $codAgente = array_key_exists('codAgente', $params) ? (string)$params['codAgente'] : null;
  1276.  
  1277. $username = array_key_exists('username', $params) ? (string)$params['username'] : null;
  1278. $password = array_key_exists('password', $params) ? (string)$params['password'] : null;
  1279. $lang = array_key_exists('lang', $params) ? (string)$params['lang'] : null;
  1280.  
  1281. try {
  1282. // Se username e password sono null significa che ancora non mi sono registrato.
  1283. // In questo caso prendo in esame solo portale e se esistono, laboratorio e fotografo
  1284. if (!empty($username) && !empty($password)) {
  1285. $loginStatus = $this->login($codPortale, $username, $password, false);
  1286. if ($loginStatus != self::LOGIN_STATUS_OK) {
  1287. $ret->setStatusMessage(GetTemaResponse::STATUS_USER_NOT_FOUND, array($codPortale, $username, $password));
  1288. return $ret;
  1289. }
  1290. }
  1291.  
  1292. $temaFiles = Fototaxi_UtilsService::getTemaFiles($codPortale, $codLaboratorio, $codFotografo, $codGruppo, $codAgente, $username, $password, $lang);
  1293.  
  1294. if ($temaFiles['notFound'] !== false) {
  1295. $ret->setStatusMessage(GetTemaResponse::STATUS_SERVER_ERROR, array("File not found: " . $temaFiles['notFound']));
  1296. return $ret;
  1297. }
  1298.  
  1299. //LOGO
  1300. $realPath = dirname(APPLICATION_PATH) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR;
  1301. $pathLogo = $realPath . $temaFiles['logo']['path'];
  1302. $LOGO = $temaFiles['logo']['filename'];
  1303. $this->logger->log(__FILE__, __LINE__, "PATH_LOGO: $pathLogo");
  1304. $imgBytes = file_get_contents($pathLogo);
  1305. if (md5(mb_convert_encoding($imgBytes, 'ISO-8859-1')) != $params['md5Logo']) {
  1306. $ret->addWrongMd5File('imgLogo', array($LOGO, new Zend_XmlRpc_Value_Base64(base64_encode($imgBytes))));
  1307. }
  1308.  
  1309. //BANNER
  1310. $pathBanner = $realPath . $temaFiles['banner']['path'];
  1311. $BANNER = $temaFiles['banner']['filename'];
  1312. $this->logger->log(__FILE__, __LINE__, "PATH_BANNER: $pathBanner");
  1313. $imgBytes = file_get_contents($pathBanner);
  1314. if (md5(mb_convert_encoding($imgBytes, 'ISO-8859-1')) != $params['md5Banner']) {
  1315. $ret->addWrongMd5File('imgBanner', array($BANNER, new Zend_XmlRpc_Value_Base64(base64_encode($imgBytes))));
  1316. }
  1317.  
  1318. // TEMA
  1319. $pathThema = $realPath . $temaFiles['tema']['path'];
  1320. $this->logger->log(__FILE__, __LINE__, "PATH_TEMA: $pathThema");
  1321. $imgBytes = file_get_contents($pathThema);
  1322. if (md5(mb_convert_encoding($imgBytes, 'ISO-8859-1')) != $params['md5Tema']) {
  1323. // il tema si chiama sempre theme.zip
  1324. $ret->addWrongMd5File('imgTema', array('theme.zip', new Zend_XmlRpc_Value_Base64(base64_encode($imgBytes))));
  1325. }
  1326.  
  1327. $ret->setStatusMessage(GetTemaResponse::STATUS_OK);
  1328. } catch (Exception $e) {
  1329. $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
  1330. $ret->setStatusMessage(GetTemaResponse::STATUS_SERVER_ERROR, array($e->getMessage()));
  1331. }
  1332.  
  1333. return $ret;
  1334. }
  1335.  
  1336. /**
  1337. * Converte stati di login a servizi esterni in codici di stato di questa classe
  1338. * @param UserItem $accountServiceLoginData
  1339. * @return int
  1340. */
  1341. private function _accountServiceLoginStatusConvertion($accountServiceLoginData)
  1342. {
  1343. $accountServiceLoginStatus = $accountServiceLoginData->getStatus();
  1344. $status = self::LOGIN_STATUS_USER_NOT_FOUND;
  1345.  
  1346. if ($accountServiceLoginStatus > 0) {
  1347. $userData = $accountServiceLoginData->getUser();
  1348. if (($accountServiceLoginStatus == UserItem::STATUS_OK_AND_DISABLED_VIRTUAL_SHOP) && ($userData['Fkruolo'] == Account_Service::USER_ROLE)) {
  1349. $status = self::EXTERNAL_LOGIN_DISABLED_VIRTUAL_SHOP;
  1350. } else {
  1351. $status = self::LOGIN_STATUS_OK;
  1352. }
  1353. } else {
  1354. switch ($accountServiceLoginStatus) {
  1355. case UserItem::STATUS_DISABLED:
  1356. case UserItem::STATUS_INACTIVE:
  1357. $status = self::LOGIN_STATUS_USER_NOT_ACTIVE;
  1358. break;
  1359. case UserItem::STATUS_WRONG_PASSWORD:
  1360. $status = self::LOGIN_STATUS_USER_WRONG_PASS;
  1361. break;
  1362. // Tutti gli altri eventuali casi sono 'not found'
  1363. }
  1364. }
  1365.  
  1366. return $status;
  1367. }
  1368.  
  1369. /**
  1370. * @param PDO $con
  1371. * @param Portali $portale
  1372. * @param Utenti $utente
  1373. * @param int $visibile
  1374. * @return array
  1375. */
  1376. private function _getCredits($con, $portale, $utente, $visibile = 1)
  1377. {
  1378. $creditList = array();
  1379.  
  1380. $coupons = CreditsQuery::create()
  1381. ->filterByCodportale($utente->getcodPortale())
  1382. ->filterByUsername($utente->getUsername())
  1383. ->filterByUtilizzabile(1)
  1384. ->addJoinObject(new Join(array(CreditsPeer::CODPORTALE, CreditsPeer::CODPROMOZIONE),
  1385. array(PromozioniPeer::CODPORTALE, PromozioniPeer::CODPROMOZIONE),
  1386. Criteria::LEFT_JOIN))
  1387. ->withColumn('Promozioni.Priorita', 'Priorita')
  1388. ->withColumn('Promozioni.Prossimoordine', 'Prossimoordine')
  1389. ->orderBy('Priorita')
  1390. ->orderByDataregistrazione()
  1391. ->orderByOraregistrazione()
  1392. ->find($con);
  1393.  
  1394. foreach ($coupons as $coupon) {
  1395. $coupon = $this->__toCredit($coupon);
  1396.  
  1397. $promoraw = PromozioniQuery::create()
  1398. ->filterByCodportale($coupon->getCodportale())
  1399. ->filterByCodpromozione($coupon->getCodpromozione())
  1400. ->where('Promozioni.Datascadenza >= ?', new DateTime())
  1401. ->findOne($con);
  1402.  
  1403. $visible = (empty($promoraw) || (!empty($promoraw) &&
  1404. (($visibile == 1 && $promoraw->getVisibile() == 0) ||
  1405. ($visibile == 0 && $promoraw->getVisibile() == 1))
  1406. )) ? false : true;
  1407.  
  1408. /*$isApplicabileClient = false;
  1409. if( !empty($promoraw) ){
  1410. $isApplicabileClient = $promoraw->getCheckclients() == 0;
  1411. if( $promoraw->getCheckclients() == 1 ){
  1412. $promozioneClients = PromozioniclientsQuery::create()
  1413. ->filterByCodportale( $promoraw->getCodportale())
  1414. ->filterByCodpromozione( $promoraw->getCodpromozione())
  1415. ->find($con);
  1416. foreach($promozioneClients as $promozioneClient){
  1417. if( $promozioneClient->getSoftware() == 'FOTOTAXIOLD'){
  1418. $isApplicabileClient = true;
  1419. break;
  1420. }
  1421. }
  1422. }
  1423. }
  1424.  
  1425. if( !empty($promoraw) ){
  1426. if($utente->getTipo() == 'F' && $promoraw->getTipofotografo()!='all'){
  1427. $fotografo = FotografiQuery::create()
  1428. ->filterByCodportale( $utente->getCodportale())
  1429. ->filterByCodlaboratorio( $utente->getCodlaboratorio())
  1430. ->filterByCodfotografo( $utente->getCodfotografo())
  1431. ->findOne($con);
  1432. if( !empty($fotografo) && $promoraw->getTipofotografo()!=$fotografo->getTipofotografo()){
  1433. $isApplicabileFotografo = false;
  1434. }
  1435. }
  1436. }*/
  1437.  
  1438. /**************************************************************************
  1439. * ESISTE LA PROMOZIONE ATTIVA SUL CREDIT ED E' APPLICABILE
  1440. **************************************************************************/
  1441. if (!(empty($promoraw)) &&
  1442. !($promoraw->getPrimoordine() == 1 && $utente->getHaveordini() != 0) &&
  1443. $visible &&
  1444. $promoraw->isApplicabileUtente($utente) &&
  1445. $promoraw->getCheckTemi() == 0 &&
  1446. $promoraw->isApplicabileClient('FOTOTAXIOLD') &&
  1447. $promoraw->isApplicabileFotografo($utente)
  1448. ) {
  1449. $promozione = new __PromozioniBean();
  1450. $promozione->fromArray($promoraw->toArray());
  1451.  
  1452. //--------------------------------------------------------------------------------------------
  1453. // SOLO PER PROMOZIONE SME : I CREDIT CON PROMOZIONE QUANTITA' OMAGGIO CON
  1454. // QTA USATE > QTA OMAGGIO IN PROMOZIONE VENGONO RESI INUTILIZZABILI
  1455. //--------------------------------------------------------------------------------------------
  1456. if ($promozione->getFlagtipopromozione() == 0 && $promozione->getQta() > 0 && $coupon->getQtausate() >= $promozione->getQta()) {
  1457. $coupon->setUtilizzabile(0);
  1458. $coupon->setQtausate($promozione->getQta());
  1459. $coupon->save($con);
  1460. } elseif ($promozione->getFlagtipopromozione() == 2 && $promozione->getValore() > 0 && $coupon->getValoreusato() > $promozione->getValore()) {
  1461. $coupon->setUtilizzabile(0);
  1462. $coupon->setValoreusato($promozione->getValore());
  1463. $coupon->save($con);
  1464. }
  1465. //--------------------------------------------------------------------------------------
  1466. // PER TUTTI GLI ALTRI CASI
  1467. //--------------------------------------------------------------------------------------
  1468. else {
  1469. //--------------------------------------------------------------
  1470. // PROMOZIONE QUANTITA OMAGGIO => CALCOLO QTA RESIDUE
  1471. //--------------------------------------------------------------
  1472. if (($promozione->getFlagtipopromozione() == 0 && $promozione->getPercsconto() == 0) || $promozione->getFlagtipopromozione() == 6) {
  1473. if ($promozione->getAscalare() == 1 && $coupon->getQtausate() != 0) {
  1474. $promozione->setQtaResidue($promozione->getQta() - $coupon->getQtausate());
  1475. } else {
  1476. $promozione->setQtaResidue($promozione->getQta());
  1477. }
  1478. }
  1479.  
  1480. //--------------------------------------------------------------
  1481. // PROMOZIONE A VALORE => CALCOLO VALORE RESIDUO
  1482. //--------------------------------------------------------------
  1483. if ($promozione->getFlagtipopromozione() == 2 || $promozione->getFlagtipopromozione() == 5 || $promozione->getFlagtipopromozione() == 6) {
  1484. if ($promozione->getAscalare() == 1 && $coupon->getValoreusato() != 0) {
  1485. $promozione->setValoreResiduo($promozione->getValore() - $coupon->getValoreusato());
  1486. } else {
  1487. $promozione->setValoreResiduo($promozione->getValore());
  1488. }
  1489. }
  1490.  
  1491. if ($promozione->getProssimoordine() == 1 && $coupon->getProssimoordine() == 0) {
  1492.  
  1493. $promozione->setDescrizione($promozione->getDescrizionealt());
  1494. $promozione->setProssimoordine($coupon->getProssimoordine());
  1495. $promozione->setQtaResidue($promozione->getQtaResidue() * $coupon->getMoltiplicatore());
  1496. $promozione->setValoreResiduo($promozione->getValoreResiduo() * $coupon->getMoltiplicatore());
  1497. $promozione->setQtaapplicasconto($promozione->getQtaapplicasconto() * $coupon->getMoltiplicatore());
  1498.  
  1499. $promozione->setCondclassearticoli("");
  1500. $promozione->setCondlistaarticoli("");
  1501. $promozione->setQtaminimaordine(0);
  1502. $promozione->setImpminimoordine(0);
  1503.  
  1504. }
  1505.  
  1506. //--------------------------------------------------------------
  1507. // AGGIUNGO IL COUPON ALLA LISTA DEI CREDITS
  1508. //--------------------------------------------------------------
  1509. if (!array_key_exists($promozione->getCodpromozione(), $creditList)) {
  1510. $creditList[$promozione->getCodpromozione()] = $promozione;
  1511. } else {
  1512. $giainserita = $creditList[$promozione->getCodpromozione()];
  1513. if (($giainserita->getFlagtipopromozione() == 0 && $giainserita->getPercsconto() == 0) || $promozione->getFlagtipopromozione() == 6) {
  1514. $giainserita->setQtaResidue($promozione->getQtaResidue() + $giainserita->getQtaResidue());
  1515. }
  1516.  
  1517. if ($promozione->getFlagtipopromozione() == 2 || $promozione->getFlagtipopromozione() == 5 || $promozione->getFlagtipopromozione() == 6) {
  1518. $giainserita->setValoreResiduo($promozione->getValoreResiduo() + $giainserita->getValoreResiduo());
  1519. }
  1520. }
  1521.  
  1522. } // Fine tutti altri casi
  1523.  
  1524.  
  1525. } // fine promozione attiva ed applicabile
  1526.  
  1527. } // fine iterazione coupon
  1528.  
  1529. return array_values($creditList);
  1530. }
  1531.  
  1532. /**
  1533. * Utilità per poter lavorare in editor con oggetti tipizzati
  1534. * @param mixed $coupon
  1535. * @return Credits
  1536. */
  1537. private function __toCredit($coupon)
  1538. {
  1539. $a = $coupon;
  1540. return $coupon;
  1541. }
  1542.  
  1543. /**
  1544. * Utilità per poter lavorare in editor con oggetti tipizzati
  1545. * @param mixed $promo
  1546. * @return __PromozioniBean
  1547. */
  1548. private function __toPromo($promo)
  1549. {
  1550. $a = $promo;
  1551. return $a;
  1552. }
  1553.  
  1554.  
  1555. /**
  1556. * Utilità per poter lavorare in editor con oggetti tipizzati
  1557. * @param $service
  1558. * @return
  1559. */
  1560. private function __toService($service)
  1561. {
  1562. $a = $service;
  1563. return $a;
  1564. }
  1565.  
  1566. private function __jsonToString($listaArticoli)
  1567. {
  1568. return !empty($listaArticoli) ? implode("|", json_decode($listaArticoli)) : "";
  1569. }
  1570.  
  1571. //------------------------------------------------------------------------------------------------------------------
  1572. // Luca Chiavelli
  1573. //------------------------------------------------------------------------------------------------------------------
  1574.  
  1575. //------------------------------------------------------------------------------------------------------------------
  1576.  
  1577. /**
  1578. * @param string $codPortale
  1579. * @param string $username
  1580. * @param string $password
  1581. * @return GetUtenteResponse
  1582. */
  1583. public function getUtente($codPortale, $username, $password)
  1584. {
  1585. $ut = new GetUtenteResponse();
  1586.  
  1587. $loginStatus = $this->login($codPortale, $username, $password, false);
  1588.  
  1589. //login fallito
  1590. if ($loginStatus != self::LOGIN_STATUS_OK) {
  1591. $ut->setStatusMessage(GetUtenteResponse::STATUS_USER_NOT_FOUND, array($codPortale, $username, $password));
  1592. return $ut;
  1593. }
  1594.  
  1595. try {
  1596. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  1597.  
  1598. $utente = UtentiQuery::create()->filterByCodportale($codPortale)
  1599. ->filterByUsername($username)
  1600. ->findOne($con);
  1601. if (empty($utente)) {
  1602. $utente = UtentiQuery::create()->filterByCodportaleold($codPortale)
  1603. ->filterByUsername($username)
  1604. ->findOne($con);
  1605. }
  1606.  
  1607. $ut->setCodPortale($utente->getCodportale());
  1608. $ut->setCodLaboratorio($utente->getCodlaboratorio());
  1609. $ut->setCodFotografo($utente->getCodfotografo());
  1610. $ut->setUsername($utente->getUsername());
  1611. $ut->setPassword($utente->getPassword());
  1612. $ut->setProvenienza($utente->getProvenienza());
  1613. $ut->setTipo($utente->getTipo());
  1614. $ut->setRuolo($utente->getFkruolo());//
  1615. $ut->setFkCategoriaUtente($utente->getFkcategoriautente());
  1616. $ut->setClassificazione($utente->getClassificazione());
  1617. $ut->setFkTipoPagamento($utente->getFktipopagamento());
  1618. $ut->setConsegna($utente->getConsegna());
  1619. $ut->setLegatoFotografo($utente->getLegatofotografo());
  1620. $ut->setRagioneSociale($utente->getRagionesociale());
  1621. $ut->setIndirizzo($utente->getIndirizzo());
  1622. $ut->setCap($utente->getCap());
  1623. $ut->setCitta($utente->getCitta());
  1624. $ut->setProvincia($utente->getProvincia());
  1625. $ut->setNazione($utente->getNazione());
  1626. $ut->setTel($utente->getTel());
  1627. $ut->setFax($utente->getFax());
  1628. $ut->setMail($utente->getMail());
  1629. $ut->setCodCard($utente->getCodcard());
  1630. $ut->setPassCard($utente->getPasscard());
  1631. $ut->setAbilitato($utente->getAbilitato());
  1632. $ut->setMaxFido($utente->getMaxfido());
  1633. $ut->setTempoFido($utente->getTempofido());
  1634. $ut->setMaxOrdineAutomatico($utente->getMaxordineautomatico());
  1635. $ut->setAttivato($utente->getAttivato());
  1636. $ut->setPiva($utente->getPiva());
  1637. } catch (Exception $e) {
  1638. $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
  1639. $ut->setStatusMessage(GetUtenteResponse::STATUS_SERVER_ERROR, $e->getMessage());
  1640. }
  1641.  
  1642. return $ut;
  1643. }
  1644.  
  1645. //------------------------------------------------------------------------------------------------------------------
  1646. /**
  1647. * @param string $codPortale
  1648. * @param string $username
  1649. * @param string $password
  1650. * @param string $numOrdine
  1651. * @return array
  1652. */
  1653. public function getOrdine($codPortale, $username, $password, $numOrdine)
  1654. {
  1655. $ut = new GetUtenteResponse();
  1656.  
  1657. $loginStatus = $this->login($codPortale, $username, $password, false);
  1658.  
  1659. //login fallito
  1660. if ($loginStatus != self::LOGIN_STATUS_OK) {
  1661. $ut->setStatusMessage(GetUtenteResponse::STATUS_USER_NOT_FOUND, array($codPortale, $username, $password));
  1662. return $ut;
  1663. }
  1664.  
  1665. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  1666.  
  1667. try {
  1668. $utente = UtentiQuery::create()->filterByCodportale($codPortale)
  1669. ->filterByUsername($username)
  1670. ->findOne($con);
  1671. if (empty($utente)) {
  1672. $utente = UtentiQuery::create()->filterByCodportaleold($codPortale)
  1673. ->filterByUsername($username)
  1674. ->findOne($con);
  1675. }
  1676. } catch (Exception $e) {
  1677. $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
  1678. $ut->setStatusMessage(GetUtenteResponse::STATUS_SERVER_ERROR, $e->getMessage());
  1679. }
  1680.  
  1681. $codLaboratorio = $utente->getCodlaboratorio();
  1682. if($utente->getConsegna()==="D"){
  1683. $fotografoPostale = FotografipostaliQuery::create()->filterByAttivo(true)->findOne($con);
  1684. $codLaboratorio = $fotografoPostale->getCodlaboratorio();
  1685. }
  1686.  
  1687. //trova ordine utente
  1688. $ord = OrdinitestataQuery::create()->filterByCodportale($utente->getCodportale())
  1689. ->filterByCodlaboratorio($codLaboratorio)
  1690. ->filterByNumordine($numOrdine)
  1691. ->findOne($con);
  1692.  
  1693. //restituisci ordine anche se vuoto;
  1694. return $ordine = array(
  1695. "codLaboratorio" => $ord->getCodlaboratorio(),
  1696. "codFotografo" => $ord->getCodfotografo(),
  1697. "numOrdine" => $ord->getNumOrdine(),
  1698. "username" => $ord->getUsername(),
  1699. "consegna" => $ord->getConsegna(),
  1700. "stato" => $ord->getStato(),
  1701. "autorizzazioneFotografo" => $ord->getAutorizzazionefotografo(),
  1702. "fkTipoPagamento" => $ord->getFkTipoPagamento(),
  1703. "packaging" => $ord->getPackaging(),
  1704. "ragioneSociale" => $ord->getRagioneSociale(),
  1705. "indirizzo" => $ord->getIndirizzo(),
  1706. "cap" => $ord->getCap(),
  1707. "citta" => $ord->getCitta(),
  1708. "provincia" => $ord->getProvincia(),
  1709. "nazione" => $ord->getNazione(),
  1710. "mail" => $ord->getMail(),
  1711. "urlServerFtp" => $ord->getUrlServerFtp(),
  1712. "urlDirFtp" => $ord->getUrlDirFtp(),
  1713. "urlTracking" => $ord->getUrlTracking(),
  1714. "nota" => $ord->getNota(),
  1715. "dataRicezioneOrdine" => $ord->getDataRicezioneOrdine(),
  1716. "dataAutorizzazioneOrdine" => $ord->getDataAutorizzazioneOrdine(),
  1717. "dataInvioLaboratorio" => $ord->getDatainviolaboratorio(),
  1718. "dataRicezioneLaboratorio" => $ord->getDataricezionelaboratorio(),
  1719. "dataStampaOrdine" => $ord->getDatastampaordine(),
  1720. "dataSpedizione" => $ord->getDataspedizione(),
  1721. "dataRicezioneFotografo" => $ord->getDataricezionefotografo(),
  1722. "valoreOrdine" => $ord->getValoreordine(),
  1723. "rifCliente" => $ord->getRifcliente(),
  1724. "rifBancaSella" => $ord->getRifbancasella(),
  1725. "percSconto" => $ord->getPercsconto(),
  1726. "impSconto" => $ord->getImpsconto(),
  1727. "desTipoSpedizione" => $ord->getDestipospedizione(),
  1728. "speseSpedizione" => $ord->getSpesespedizione(),
  1729. );
  1730. }
  1731.  
  1732. //------------------------------------------------------------------------------------------------------------------
  1733. // IMPLEMENTATO X GESTIONE BROWSER NON MODALE
  1734. //------------------------------------------------
  1735. /**
  1736. * @param string $codPortale
  1737. * @param string $codLaboratorio
  1738. * @param string $codFotografo
  1739. * @param string $numOrdine
  1740. * @return int
  1741. */
  1742. public function getOrderStatus($codPortale, $codLaboratorio, $codFotografo, $numOrdine)
  1743. {
  1744. $status = 999;
  1745.  
  1746. $unicredit = new Batch_PagamentiUnicredit();
  1747. $unicredit->verificaPagamentiUnicredit("LAST_HOUR");
  1748.  
  1749. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  1750.  
  1751. $ord = OrdinitestataQuery::create()->filterByCodlaboratorio($codLaboratorio)
  1752. ->filterByCodportale($codPortale)
  1753. ->filterByCodfotografo($codFotografo)
  1754. ->filterByNumordine($numOrdine)
  1755. ->findOne($con);
  1756.  
  1757. //cascata per cercare di trovare lo stato di un ordine domicilio
  1758. if(empty($ord))
  1759. {
  1760. $fotografoPostale = FotografipostaliQuery::create()->filterByAttivo(true)->findOne($con);
  1761. $ord = OrdinitestataQuery::create()->filterByCodlaboratorio($fotografoPostale->getCodlaboratorio())
  1762. ->filterByCodportale($codPortale)
  1763. ->filterByNumordine($numOrdine)
  1764. ->findOne($con);
  1765. }
  1766.  
  1767. if(empty($ord))
  1768. {
  1769. $ord = OrdinitestataQuery::create()->filterByCodportale($codPortale)
  1770. ->filterByNumordine($numOrdine)
  1771. ->filterByConsegna("D")
  1772. ->orderByDataricezioneordine("desc")
  1773. ->findOne($con);
  1774. }
  1775.  
  1776. if ($ord != null) {
  1777. $status = $ord->getStato();
  1778. }
  1779.  
  1780. return intval($status);
  1781. }
  1782.  
  1783. //------------------------------------------------------------------------------------------------------------------
  1784. /**
  1785. * @param array $articolo
  1786. * @param struct $utente
  1787. * @param array $fotografo
  1788. * @return array
  1789. */
  1790. private static function getListino($articolo, $utente, $fotografo)
  1791. {
  1792. $listino = null;
  1793.  
  1794. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  1795.  
  1796. $listinoFotografo = ListiniQuery::create()->filterByCodportale($utente->getCodportale())
  1797. ->filterByCodlaboratorio($utente->getCodlaboratorio())
  1798. ->filterByCodlistino($fotografo->getCodpersonalizzato())
  1799. ->filterByCodarticolo($articolo->getCodarticolo())
  1800. ->findOne($con);
  1801.  
  1802. if ($utente->getLegatoFotografo() == 1 && !empty($listinoFotografo)) {
  1803. $listino = $listinoFotografo;
  1804. }
  1805.  
  1806. $listinoLaboratorio = ListiniQuery::create()->filterByCodportale($utente->getCodportale())
  1807. ->filterByCodlaboratorio($utente->getcodLaboratorio())
  1808. ->filterByCodlistino('0')
  1809. ->filterByCodarticolo($articolo->getCodarticolo())
  1810. ->findOne($con);
  1811.  
  1812. if (empty($listino) && !empty($listinoLaboratorio)) {
  1813. $listino = $listinoLaboratorio;
  1814. }
  1815.  
  1816. $listinoPortale = ListiniQuery::create()->filterByCodportale($utente->getCodportale())
  1817. ->filterByCodlaboratorio('0')
  1818. ->filterByCodlistino('0')
  1819. ->filterByCodarticolo($articolo->getCodarticolo())
  1820. ->findOne($con);
  1821.  
  1822. if (empty($listino) && !empty($listinoPortale)) {
  1823. $listino = $listinoPortale;
  1824. }
  1825.  
  1826. return $listino;
  1827.  
  1828. }
  1829.  
  1830. //------------------------------------------------------------------------------------------------------------------
  1831. /**
  1832. * @param array $e
  1833. * @return string
  1834. */
  1835. public function getResponseException($e)
  1836. {
  1837. $message = '<?xml version="1.0" encoding="ISO-8859-1"?><methodResponse><fault><value><struct><member><name>faultString</name><value>org.apache.xmlrpc.XmlRpcException: ';
  1838. $message .= $e->getMessage() . " " . $e->getTraceAsString();
  1839. $message .= '</value></member><member><name>faultCode</name><value><int>';
  1840. $message .= $e->getCode();
  1841. $message .= '</int></value></member></struct></value></fault></methodResponse>';
  1842.  
  1843. return $message;
  1844. }
  1845.  
  1846. //------------------------------------------------------------------------------------------------------------------
  1847. // PYTAXY LOGGER
  1848. //------------------------------------------------------------------------------------------------------------------
  1849. /**
  1850. * @param string $msgerr
  1851. */
  1852. public function printClientErr($msgerr)
  1853. {
  1854. $this->logger->log(__FILE__, __LINE__, "LOG PYTAXI ERROR: " . $msgerr, Zend_Log::ERR);
  1855. }
  1856.  
  1857. //------------------------------------------------------------------------------------------------------------------
  1858. /**
  1859. * map=(codPortale, username, password)
  1860. *
  1861. * @param struct $map
  1862. * @param string $tipoServizio
  1863. * @return array
  1864. */
  1865. public function getArticoli($map, $tipoServizio)
  1866. {
  1867. try {
  1868. $ut = new GetUtenteResponse();
  1869.  
  1870. $loginStatus = $this->login($map["codPortale"], $map["username"], $map["password"], false);
  1871.  
  1872. //login fallito
  1873. if ($loginStatus != self::LOGIN_STATUS_OK) {
  1874. $ut->setStatusMessage(GetUtenteResponse::STATUS_USER_NOT_FOUND, array($map["codPortale"], $map["username"], $map["password"]));
  1875. return $ut;
  1876. }
  1877.  
  1878. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  1879.  
  1880. try {
  1881. $utente = UtentiQuery::create()->filterByCodportale($map["codPortale"])
  1882. ->filterByUsername($map["username"])
  1883. ->findOne($con);
  1884.  
  1885. if (empty($utente)) {
  1886. $utente = UtentiQuery::create()->filterByCodportaleold($map["codPortale"])
  1887. ->filterByUsername($map["username"])
  1888. ->findOne($con);
  1889. }
  1890. } catch (Exception $e) {
  1891. $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
  1892. $ut->setStatusMessage(GetUtenteResponse::STATUS_SERVER_ERROR, $e->getMessage());
  1893. }
  1894.  
  1895. $codPortale = $utente != null ? $utente->getCodPortale() : $map["codPortale"];
  1896.  
  1897. //------------------------------------------
  1898.  
  1899. $portale = PortaliQuery::create()->filterByCodportale($codPortale)
  1900. ->findOne($con);
  1901. if ($portale == null) {
  1902. throw new Exception("Portale non Esistente per portale: " . $codPortale);
  1903. }
  1904.  
  1905. if ($portale->getTipoPortale() == "D" || $utente->getCodFotografo() == 0) {
  1906. $fotografo = FotografiQuery::create()->filterByCodportale($utente->getCodPortale())
  1907. ->filterByAbilitato('1')
  1908. ->findOne($con);
  1909. } else {
  1910. $fotografo = FotografiQuery::create()->filterByCodportale($utente->getCodPortale())
  1911. ->filterByCodlaboratorio($utente->getCodLaboratorio())
  1912. ->filterByCodfotografo($utente->getCodFotografo())
  1913. ->findOne($con);
  1914. }
  1915.  
  1916. if ($fotografo == null) {
  1917. throw new Exception("Fotografo non Esistente per portale: " . $portale->getCodPortale() . " username: " . $utente->getUsername());
  1918. }
  1919.  
  1920. $codLaboratorio = $utente->getCodlaboratorio();
  1921.  
  1922. $articoliList = ArticoliQuery::create()->filterByCodportale($portale->getCodPortale())
  1923. ->filterByCodlaboratorio($codLaboratorio)
  1924. ->filterByFlagtipoutente(array($utente->getTipo(), 'B'))
  1925. ->filterByFktiposervizio($tipoServizio)
  1926. ->filterByVisualizzabile(array(1, 2, 3))
  1927. /*->condition('cond1', 'Articoli.flagTipoUtente = ?', $utente->getTipo())
  1928. ->condition('cond2', 'Articoli.flagTipoUtente = ?', 'B')
  1929. ->combine(array('cond1', 'cond2'), 'or', 'cond12')
  1930. ->condition('cond5', 'visualizzabile = ?', '1')
  1931. ->condition('cond6', 'visualizzabile = ?', '2')
  1932. ->condition('cond7', 'visualizzabile = ?', '3')
  1933. ->combine(array('cond5', 'cond6', 'cond7'), 'or', 'cond567')
  1934. ->condition('cond3', 'fkTipoServizio = ?', $tipoServizio)
  1935. ->where(array('cond12', 'cond3', 'cond567'), 'and')*/
  1936. ->find($con);
  1937.  
  1938. if ($articoliList == null || empty($articoliList)) {
  1939. $articoliList = ArticoliQuery::create()->filterByCodportale($portale->getCodPortale())
  1940. ->filterByFlagtipoutente(array($utente->getTipo(), 'B'))
  1941. ->filterByFktiposervizio($tipoServizio)
  1942. ->filterByVisualizzabile(array(1, 2, 3))
  1943. ->find($con);
  1944. }
  1945.  
  1946. if ($articoliList == null) {
  1947. throw new Exception("Articoli non Presenti per portale: " . $codPortale . " username: " . $map["username"] . " password: " . $map["password"]);
  1948. }
  1949.  
  1950. $listiniFotografo = ListiniQuery::create()->filterByCodportale($utente->getCodPortale())
  1951. ->filterByCodlaboratorio($utente->getCodLaboratorio())
  1952. ->filterByCodlistino($fotografo->getCodpersonalizzato())
  1953. ->filterByCodpersonalizzato('0')
  1954. ->find($con);
  1955.  
  1956. $listiniLaboratorio = ListiniQuery::create()->filterByCodportale($utente->getCodPortale())
  1957. ->filterByCodlaboratorio($utente->getCodLaboratorio())
  1958. ->filterByCodlistino('0')
  1959. ->filterByCodpersonalizzato('0')
  1960. ->find($con);
  1961.  
  1962. $listiniPortale = ListiniQuery::create()->filterByCodportale($utente->getCodPortale())
  1963. ->filterByCodlaboratorio('0')
  1964. ->filterByCodlistino('0')
  1965. ->filterByCodpersonalizzato('0')
  1966. ->find($con);
  1967.  
  1968.  
  1969. $articoliMap = array();
  1970.  
  1971. foreach ($articoliList as $articolo) {
  1972. $articolo->setArticoloTransfert($fotografo, $utente->getLegatofotografo(), $utente->getTipo());
  1973.  
  1974. $listino = null;
  1975.  
  1976. //listino personalizzato fotografo
  1977. //if ($utente->getLegatofotografo() == 1 && ($listiniFotografo != null || !empty($listiniFotografo))) {
  1978. $applicaListinoFotografo = $utente->getCodportale() == "rikorda" ? ($utente->getFkruolo() == Account_Service::SHOP_ROLE) : ($utente->getLegatofotografo() == 1);
  1979. if ( $applicaListinoFotografo && ($listiniFotografo != null || !empty($listiniFotografo))) {
  1980. foreach ($listiniFotografo as $lF) {
  1981. if ($lF->getCodArticolo() == $articolo->getCodArticolo()) {
  1982. $listino = $lF;
  1983. break;
  1984. }
  1985. }
  1986. }
  1987.  
  1988. //listino laboratorio
  1989. if ($listino == null && ($listiniLaboratorio != null || !empty($listiniLaboratorio))) {
  1990. foreach ($listiniLaboratorio as $lL) {
  1991. if ($lL->getCodArticolo() == $articolo->getCodArticolo()) {
  1992. $listino = $lL;
  1993. break;
  1994. }
  1995. }
  1996. }
  1997.  
  1998. //listino portale
  1999. if ($listino == null && ($listiniPortale != null || !empty($listiniPortale))) {
  2000. foreach ($listiniPortale as $lP) {
  2001. if ($lP->getCodArticolo() == $articolo->getCodArticolo()) {
  2002. $listino = $lP;
  2003. break;
  2004. }
  2005. }
  2006. }
  2007.  
  2008. if ($listino != null) {
  2009. $articolo->setListino($listino);
  2010. $articoliMap[$articolo->getCodArticolo()] = $articolo->getArticoloAsMap();//vorrebbe una mappa
  2011.  
  2012. } else {
  2013. throw new Exception("Listino non presente per portale: " . $utente->getCodportale() . " username: " . $utente->getUsername() . " password: " . $utente->getPassword() . " articolo: " . $articolo->getCodArticolo());
  2014. }
  2015. }
  2016. return $articoliMap;
  2017. } catch (Exception $e) {
  2018. $e->getTrace();
  2019. throw new Exception($e->getMessage());
  2020. }
  2021.  
  2022. }
  2023.  
  2024. //----------------------------------------------------------------------
  2025. // PER BUG ASSEMBLATORE
  2026. //----------------------------------------------------------------------
  2027. /**
  2028. * @param string $codLaboratorio
  2029. * @return array
  2030. * @throws Exception
  2031. */
  2032. public function getArticoliAssemblatore($codLaboratorio)
  2033. {
  2034. $articoliMap = array();
  2035.  
  2036. try {
  2037. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2038. //-----------------------------------------------------
  2039. // CONTROLLO PARAMETRI OBBLIGATORI
  2040. //-----------------------------------------------------
  2041. if ($codLaboratorio == null) {
  2042. throw new Exception("Parametri obbligatori mancanti: COD.LABORATORIO" . $codLaboratorio);
  2043. }
  2044.  
  2045. $sql_where = "Articoli.codLaboratorio='" . $codLaboratorio . "' order by Portali.prioritaAssemblatore, Articoli.codArticolo";
  2046.  
  2047. $articoliList = ArticoliQuery::create()->addJoinObject(new Join(array(ArticoliPeer::CODPORTALE),
  2048. array(PortaliPeer::CODPORTALE),
  2049. Criteria::LEFT_JOIN))
  2050. ->where($sql_where)
  2051. ->find($con);
  2052.  
  2053. foreach ($articoliList as $articolo) {
  2054. if ($articoliMap[$articolo->getCodArticolo()] == null) {
  2055. $articoliMap[strtolower($articolo->getCodArticolo())] = $articolo->getArticoloAsMap();
  2056. }
  2057. }
  2058.  
  2059. return $articoliMap;
  2060.  
  2061. } catch (Exception $e) {
  2062. $e->getTrace();
  2063. throw new Exception($e->getMessage());
  2064. }
  2065. }
  2066.  
  2067. //------------------------------------------------------------------------------------------------------------------
  2068. // OFFLINE - CREAZIONE PACCHETTO/DOWNLOAD AGGIORNAMENTI
  2069. //------------------- --------------------------------------
  2070. /**
  2071. * @param struct $map
  2072. * @return struct
  2073. * @throws Exception
  2074. */
  2075. public function getArticoliPacchetto($map)
  2076. {
  2077. try {
  2078. //-----------------------------------------------------
  2079. // CONTROLLO PARAMETRI OBBLIGATORI
  2080. //-----------------------------------------------------
  2081. if ($map["codLaboratorio"] == null || $map["tipoUtente"] == null || $map["modalita"] == null || $map["legatoFotografo"] == null) {
  2082. throw new Exception("Parametri obbligatori mancanti: COD.LABORATORIO" . $map["codLaboratorio"] . " TIPO UTENTE:" . $map["tipoUtente"] . " MODALITA:" . $map["modalita"] . " LEGATO FOTOGRAFO:" . $map["legatoFotografo"]);
  2083. }
  2084.  
  2085. //----------------------------------------------------
  2086. // CONVERSIONE PORTALE
  2087. //----------------------------------------------------
  2088. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2089.  
  2090. $cp = ConversioneportaliQuery::create()->filterByCodportaleold($map["codPortale"])
  2091. ->filterByCodlaboratorioold('0')
  2092. ->filterByCodfotografoold('0')
  2093. ->filterByCodgruppoold('')
  2094. ->findOne($con);
  2095.  
  2096. $codPortale = $cp != null ? $cp->getCodportalenew() : (string)$map["codPortale"];
  2097.  
  2098. //----
  2099.  
  2100. $portale = PortaliQuery::create()->filterByCodportale($codPortale)
  2101. ->findOne($con);
  2102.  
  2103. if ($portale == null) {
  2104. throw new Exception("Portale non Esistente: " . $codPortale);
  2105. }
  2106.  
  2107. //------------------------------------
  2108. // PARAMETRI
  2109. //------------------------------------
  2110. $codLaboratorio = (string)$map["codLaboratorio"];
  2111.  
  2112. $tipoUtente = (string)$map["tipoUtente"];
  2113.  
  2114. $modalita = intval((string)$map["modalita"]);
  2115.  
  2116. $legatoFotografo = intval((string)$map["legatoFotografo"]);
  2117.  
  2118. $fotografo = null;
  2119.  
  2120. if ($map["codFotografo"] != null) {
  2121. $fotografo = FotografiQuery::create()->filterByCodportale($portale->getCodPortale())
  2122. ->filterByCodlaboratorio($codLaboratorio)
  2123. ->filterByCodfotografo($map["codFotografo"])
  2124. ->findOne($con);
  2125.  
  2126. if ($fotografo == null) {
  2127. throw new Exception("Fotografo non Esistente: " . $map["codFotografo"]);
  2128. }
  2129.  
  2130. }
  2131.  
  2132. //---------------------------------------------------
  2133. // PRENDE SOLO I SERVIZI ASSOCIATI AL LABORATORIO
  2134. //---------------------------------------------------
  2135. //$sql1 = "left join ServiziLaboratori on ( Servizi.codPortale=ServiziLaboratori.codPortale and Servizi.codServizio=ServiziLaboratori.codServizio) where Servizi.codPortale='" . $portale->getCodportale() . "' and ServiziLaboratori.codLaboratorio='" . $codLaboratorio . "'";
  2136. //->condition($sql1)->find($con)->toArray();
  2137.  
  2138. $serviziList = ServiziQuery::create()->filterByCodportale($codPortale)
  2139. ->addJoinObject(new Join(array(ServiziPeer::CODPORTALE, ServiziPeer::CODSERVIZIO),
  2140. array(ServizilaboratoriPeer::CODPORTALE, ServizilaboratoriPeer::CODSERVIZIO),
  2141. Criteria::LEFT_JOIN))
  2142. ->withColumn('ServiziLaboratori.Codlaboratorio', 'Codlaboratorio')
  2143. ->where("ServiziLaboratori.CodLaboratorio = $codLaboratorio")
  2144. ->find($con);
  2145.  
  2146. $servizi = "";
  2147. $count = 1;
  2148.  
  2149. //SE NON CI SONO SERVIZI ASSOCIATI AL LABORATORIO PRENDE DI DEFAULT STAMPA FOTO
  2150. if (count($serviziList) == 0) {
  2151. $servizi = "'SS'";
  2152. } else {
  2153. foreach ($serviziList as $servizio) {
  2154. $servizi .= "'" . $servizio->getFkTipoServizio() . "'";
  2155. $servizi .= ($count < count($serviziList) ? "," : "");
  2156. $count++;
  2157. }
  2158. }
  2159.  
  2160. /************************************************************************************
  2161. * per modalita mista devono essere scaricati tutti gli articoli
  2162. * per tutte le altre devono essere scaricati articoli con flag=0 o flag=modalita
  2163. ***********************************************************************************/
  2164. $sql2 = "codPortale='" . $portale->getCodportale() . "' and codLaboratorio='" . $codLaboratorio . "' and ( flagTipoUtente='" . $tipoUtente . "' or flagTipoUtente='B' ) and (visualizzabile=1 or visualizzabile=2 or visualizzabile=3) and fkTipoServizio in (" . $servizi . ")";
  2165.  
  2166. if ($modalita == 1 || $modalita == 2) {
  2167. $sql2 .= " and ( flagModalita=0 or flagModalita=" . $modalita . ")";
  2168. }
  2169.  
  2170. $this->logger->log(__FILE__, __LINE__, "QUERY GET ARTICOLI PACCHETTO " . $sql2, Zend_Log::INFO);
  2171.  
  2172. $articoliList = ArticoliQuery::create()->where($sql2)->find($con);
  2173.  
  2174. if ($articoliList == null) {
  2175. throw new Exception("Articoli non Presenti per portale: " . $map["codPortale"] . " laboratorio: " . $map["codLaboratorio"] . " tipoUtente: " . $map["tipoUtente"] . " modalita: " . $map["modalita"]);
  2176. }
  2177.  
  2178. $listiniFotografo = null;
  2179. if ($fotografo != null) {
  2180. $listiniFotografo = ListiniQuery::create()->filterByCodportale($portale->getCodportale())
  2181. ->filterByCodlaboratorio($codLaboratorio)
  2182. ->filterByCodlistino($fotografo->getCodpersonalizzato())
  2183. ->filterByCodpersonalizzato('0')
  2184. ->find($con);
  2185. }
  2186.  
  2187. $listiniLaboratorio = ListiniQuery::create()->filterByCodportale($portale->getCodportale())
  2188. ->filterByCodlaboratorio($codLaboratorio)
  2189. ->filterByCodlistino('0')
  2190. ->filterByCodpersonalizzato('0')
  2191. ->find($con);
  2192.  
  2193. $listiniPortale = ListiniQuery::create()->filterByCodportale($portale->getCodportale())
  2194. ->filterByCodlaboratorio('0')
  2195. ->filterByCodlistino('0')
  2196. ->filterByCodpersonalizzato('0')
  2197. ->find($con);
  2198.  
  2199.  
  2200. $articoliServiziMap = array();
  2201.  
  2202. foreach ($articoliList as $articolo) {
  2203. $articolo->setArticoloTransfert($fotografo, $legatoFotografo, $tipoUtente);
  2204.  
  2205. $listino = null;
  2206.  
  2207. $codArt = $articolo->getCodarticolo();//test
  2208.  
  2209. //listino personalizzato fotografo
  2210. //if (($legatoFotografo == 1) && (count($listiniFotografo) > 0)) {
  2211. if (($tipoUtente == 'F') && (count($listiniFotografo) > 0)) {
  2212. foreach ($listiniFotografo as $lF) {
  2213. if ($lF->getCodarticolo() == $articolo->getCodArticolo()) {
  2214. $listino = $lF;
  2215. break;
  2216. }
  2217. }
  2218. }
  2219.  
  2220. //listino laboratorio
  2221. if (empty($listino) && (count($listiniLaboratorio) > 0)) {
  2222. foreach ($listiniLaboratorio as $lL) {
  2223. $codlL = $lL->getCodArticolo();//test
  2224.  
  2225. if ($lL->getCodArticolo() == $articolo->getCodArticolo()) {
  2226. $listino = $lL;
  2227. break;
  2228. }
  2229. }
  2230. }
  2231.  
  2232. //listino portale
  2233. if (empty($listino) && (count($listiniPortale) > 0)) {
  2234. foreach ($listiniPortale as $lP) {
  2235. $codlP = $lP->getCodArticolo();//test
  2236.  
  2237. if ($lP->getCodarticolo() == $articolo->getCodarticolo()) {
  2238. $listino = $lP;
  2239. break;
  2240. }
  2241. }
  2242. }
  2243.  
  2244. if ($listino != null) {
  2245. $articolo->setListino($listino);
  2246.  
  2247. if ($articoliServiziMap[$articolo->getFkTipoServizio()] == null) {
  2248. $articoliMap = array();
  2249. $articoliMap[$articolo->getCodArticolo()] = $articolo->getArticoloAsMap();//si aspetta una mappa
  2250.  
  2251. $articoliServiziMap[$articolo->getFkTipoServizio()] = $articoliMap;
  2252. } else {
  2253. $articoliMap = $articoliServiziMap[$articolo->getFkTipoServizio()];
  2254. $articoliMap[$articolo->getCodArticolo()] = $articolo->getArticoloAsMap();
  2255. $articoliServiziMap[$articolo->getFkTipoServizio()] = $articoliMap;
  2256. }
  2257. } else {
  2258. throw new Zend_XmlRpc_Exception("Listino non presente per portale: " . $portale->getCodPortale() . " laboratorio: " . $codLaboratorio . " articolo: " . $articolo->getCodArticolo());
  2259. }
  2260. }
  2261.  
  2262. return $articoliServiziMap;
  2263.  
  2264. } catch (Exception $e) {
  2265. $e->getTrace();
  2266. throw new Exception($e->getMessage());
  2267. }
  2268.  
  2269. }
  2270.  
  2271. //--------------------------------------------------------------------------------------
  2272. /**
  2273. * @param array $errorMap
  2274. * @param string $codeError
  2275. * @param string $message
  2276. */
  2277. private static function addMsgToErrorMap($errorMap, $codeError, $message)
  2278. {
  2279. $systemError = array();
  2280. $messageError = array();
  2281.  
  2282. if ($errorMap['0'] != null) {
  2283. $systemError = $errorMap['0'];
  2284. }
  2285. if ($errorMap['1'] != null) {
  2286. $messageError = $errorMap['1'];
  2287. }
  2288. if ($codeError == "0") {
  2289. array_push($systemError, $message);
  2290. $errorMap["0"] = $systemError;
  2291. } else {
  2292. array_push($messageError, $message);
  2293. $errorMap["1"] = $messageError;
  2294. }
  2295.  
  2296. return $errorMap;
  2297. }
  2298.  
  2299. //---------------------------------------------------------------------------------------
  2300. // FONT LIST
  2301. //---------------------------------------------------------------------------------------
  2302. /**
  2303. * @param string $so
  2304. * @return array
  2305. */
  2306. public function getFontList($so)
  2307. {
  2308. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2309.  
  2310. $fontList = FontQuery::create()->filterBySistemaOperativo($so)
  2311. ->find($con);
  2312.  
  2313. for ($i = 0; $i < count($fontList); $i++) {
  2314. $fontMap[$fontList[$i]->getNome()] = array(intval($fontList[$i]->getTolleranza()), $fontList[$i]->getPredefinito());
  2315. }
  2316.  
  2317. return $fontMap;
  2318. }
  2319.  
  2320. //------------------------------------------------------------------------------------------------------------------
  2321. // FONT
  2322. //------------------------------------------------------------------------------------------------------------------
  2323. /* EARLTP: porting di un metodo java per fototaxi, di fatto non serve
  2324. * NON USATO
  2325. *
  2326. * @param array $pathFont
  2327. * @return array
  2328. */
  2329.  
  2330. public function getFontsFile($pathFont)
  2331. {
  2332. $config = Zend_Registry::get('Redarea_Configuration');
  2333.  
  2334. $pathDir = $config->path->var_labo . "/SERVIZI/font";
  2335.  
  2336. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2337.  
  2338. for ($i = 0; $i < count($pathFont); $i++)//rows as row
  2339. {
  2340. $so = substr($pathFont[$i], 0, strrpos($pathFont[$i], "/"));//
  2341. $nomeFont = substr($pathFont[$i], strrpos($pathFont[$i], "/") + 1, strlen($pathFont[$i]));//nome del file-> da ultimo / a fine path
  2342.  
  2343. $path = $pathDir . "/" . $pathFont[$i];//path completo
  2344.  
  2345. $fb = FontQuery::create()->filterBySistemaOperativo($so)
  2346. ->filterByNome($nomeFont)
  2347. ->findOne($con);
  2348.  
  2349. if (file_exists($path) && $fb != null) {
  2350. //$imgBytes = $this->getByteFromFile($path);
  2351. $imgBytes = file($path);
  2352. $string = implode($imgBytes);
  2353. $resultMap[$pathFont[$i]] = base64_encode($string);
  2354. }
  2355. }
  2356.  
  2357. return $resultMap;
  2358.  
  2359. }
  2360. //------------------------------------------------------------------------------------------------------------------
  2361. /**
  2362. * @param struct $map
  2363. * @return array
  2364. * @throws Exception
  2365. * @throws ServiceException
  2366. */
  2367. public function getSpeseSpedizione($map)
  2368. {
  2369. $ut = new GetUtenteResponse();
  2370.  
  2371. $loginStatus = $this->login($map['codPortale'], $map['username'], $map['password'], false);
  2372.  
  2373. //login fallito
  2374. if ($loginStatus != self::LOGIN_STATUS_OK) {
  2375. $ut->setStatusMessage(GetUtenteResponse::STATUS_USER_NOT_FOUND, array($map['codPortale'], $map['username'], $map['password']));
  2376. return $ut;
  2377. }
  2378.  
  2379. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2380.  
  2381. try {
  2382. $utente = UtentiQuery::create()->filterByCodportale($map['codPortale'])
  2383. ->filterByUsername($map['username'])
  2384. ->findOne($con);
  2385. if (empty($utente)) {
  2386. $utente = UtentiQuery::create()->filterByCodportaleold($map['username'])
  2387. ->filterByUsername($map['username'])
  2388. ->findOne($con);
  2389. }
  2390. } catch (Exception $e) {
  2391. $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
  2392. $ut->setStatusMessage(GetUtenteResponse::STATUS_SERVER_ERROR, $e->getMessage());
  2393. }
  2394.  
  2395. $codPortale = $utente != null ? $utente->getCodPortale() : $map['codPortale'];
  2396.  
  2397. //----------------
  2398.  
  2399. $portale = PortaliQuery::create()->filterByCodportale($codPortale)
  2400. ->findOne($con);
  2401.  
  2402. if ($utente == null) {
  2403. throw new Exception("Utente non esistente per portale: " . $codPortale);
  2404. }
  2405.  
  2406. //----------------
  2407.  
  2408. /*// COMMENTO JAVA //
  2409. per messa online paypal int version = map.get("version") == null ? 0 : Integer.parseInt(map.get("version").toString());
  2410.  
  2411. per messa online paypal
  2412.  
  2413. if( version < 15105 && "3".equals(rs.getString("codModalita"))){
  2414. continue;
  2415. }*/
  2416.  
  2417. try {
  2418. $sql = "select distinct SpeseSpedizione.codModalita, desModalita, SpeseSpedizione.codSpedizione, desSpedizione, SpeseSpedizione.codPackaging, desPackaging, pesoDa, pesoA, SpeseSpedizione.costo, ModPagamento.costo as costoPagamento, TipoSpedizione.costo as costoSpedizione, Packaging.costo as costoPackaging, forzaSpedizione from SpeseSpedizione left join ModPagamento on SpeseSpedizione.codModalita=ModPagamento.codModalita left join TipoSpedizione on SpeseSpedizione.codSpedizione=TipoSpedizione.codSpedizione left join Packaging on SpeseSpedizione.codPackaging=Packaging.codPackaging where SpeseSpedizione.codPortale='" . $portale->getCodportale() . "' and ModPagamento.codPortale='" . $portale->getCodportale() . "' and TipoSpedizione.codPortale='" . $portale->getCodportale() . "' and Packaging.codPortale='" . $portale->getCodportale() . "' order by desModalita, desSpedizione, desPackaging, pesoDa";
  2419. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2420. $stmt = $con->prepare($sql);
  2421. if ($stmt->execute()) {
  2422. $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
  2423.  
  2424. $spese = array();
  2425. $spesa = array();
  2426.  
  2427. foreach ($rows as $row) {
  2428. $spesa["codModalita"] = $row["codModalita"];
  2429. $spesa["modalita"] = $row["desModalita"];
  2430. $spesa["codSpedizione"] = $row["codSpedizione"];
  2431. $spesa["spedizione"] = $row["desSpedizione"];
  2432. $spesa["codPackaging"] = $row["codPackaging"];
  2433. $spesa["packaging"] = $row["desPackaging"];
  2434.  
  2435. $spesa["pesoDa"] = $row["pesoDa"];
  2436. $spesa["pesoA"] = $row["pesoA"];
  2437.  
  2438. $spesa["costo"] = $row["costo"];
  2439.  
  2440. //Costi aggiuntivi fissi
  2441. $spesa["costoPagamento"] = $row["costoPagamento"];
  2442. $spesa["costoSpedizione"] = $row["costoSpedizione"];
  2443. $spesa["costoPackaging"] = $row["costoPackaging"];
  2444.  
  2445. $spesa["forzaSpedizione"] = $row["forzaSpedizione"];
  2446.  
  2447.  
  2448. array_push($spese, $spesa);//aggiunge spesa a spese
  2449. }
  2450. }
  2451. } catch (Exception $e) {
  2452. $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
  2453. $this->logger->log(__FILE__, __LINE__, $e->getTraceAsString(), Zend_Log::ERR);
  2454. throw new ServiceException($e->getMessage());
  2455. }
  2456.  
  2457. return $spese;
  2458. }
  2459.  
  2460. //------------------------------------------------------------------------------------------------------------------
  2461. /**
  2462. * @param string $codPortale
  2463. * @return array
  2464. * @throws Exception
  2465. * @throws string
  2466. */
  2467. public function getSpeseSpedizionePacchetto($codPortale)
  2468. {
  2469. //----------------------------------------------------
  2470. // CONVERSIONE PORTALE
  2471. //----------------------------------------------------
  2472. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2473. $cp = ConversioneportaliQuery::create()->filterByCodportaleold($codPortale)
  2474. ->filterByCodlaboratorioold('0')
  2475. ->filterByCodfotografoold('0')
  2476. ->filterByCodgruppoold()
  2477. ->findOne($con);
  2478. $codPortale = $cp != null ? $cp->getCodportalenew() : $codPortale;
  2479. //------------------
  2480.  
  2481. $portale = PortaliQuery::create()->filterByCodportale($codPortale)
  2482. ->findOne($con);
  2483. if ($portale == null) {
  2484. throw new Exception("Portale non Esistente per portale: " . $codPortale);
  2485. }
  2486.  
  2487. $spese = array();
  2488.  
  2489. try {
  2490. $sql = "select distinct SpeseSpedizione.codModalita, desModalita, SpeseSpedizione.codSpedizione, desSpedizione, SpeseSpedizione.codPackaging, desPackaging, pesoDa, pesoA, SpeseSpedizione.costo, ModPagamento.costo as costoPagamento, TipoSpedizione.costo as costoSpedizione, Packaging.costo as costoPackaging, forzaSpedizione from SpeseSpedizione left join ModPagamento on SpeseSpedizione.codModalita=ModPagamento.codModalita left join TipoSpedizione on SpeseSpedizione.codSpedizione=TipoSpedizione.codSpedizione left join Packaging on SpeseSpedizione.codPackaging=Packaging.codPackaging where SpeseSpedizione.codPortale='" . $portale->getCodPortale() . "' and ModPagamento.codPortale='" . $portale->getCodPortale() . "' and TipoSpedizione.codPortale='" . $portale->getCodPortale() . "' and Packaging.codPortale='" . $portale->getCodPortale() . "' order by desModalita, desSpedizione, desPackaging, pesoDa";
  2491. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2492. $stmt = $con->prepare($sql);
  2493.  
  2494. if ($stmt->execute()) {
  2495. $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);//prende qualcosa ma forse i dati non ci sono
  2496.  
  2497. $spesa = array();
  2498.  
  2499. foreach ($rows as $row) {
  2500. $spesa["codModalita"] = $row["codModalita"];
  2501. $spesa["modalita"] = $row["desModalita"];
  2502. $spesa["codSpedizione"] = $row["codSpedizione"];
  2503. $spesa["spedizione"] = $row["desSpedizione"];
  2504. $spesa["codPackaging"] = $row["codPackaging"];
  2505. $spesa["packaging"] = $row["desPackaging"];
  2506.  
  2507. $spesa["pesoDa"] = $row["pesoDa"];
  2508. $spesa["pesoA"] = $row["pesoA"];
  2509.  
  2510. $spesa["costo"] = $row["costo"];
  2511.  
  2512. //Costi aggiuntivi fissi
  2513. $spesa["costoPagamento"] = $row["costoPagamento"];
  2514. $spesa["costoSpedizione"] = $row["costoSpedizione"];
  2515. $spesa["costoPackaging"] = $row["costoPackaging"];
  2516.  
  2517. $spesa["forzaSpedizione"] = $row["forzaSpedizione"];
  2518.  
  2519. array_push($spese, $spesa);//aggiunge spesa a spese
  2520. }
  2521. }
  2522. } catch (Exception $e) {
  2523. $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
  2524. $this->logger->log(__FILE__, __LINE__, $e->getTraceAsString(), Zend_Log::ERR);
  2525. throw new ServiceException($e->getMessage());
  2526. }
  2527.  
  2528. return $spese;
  2529. }
  2530.  
  2531. //------------------------------------------------------------------------------------------------------------------
  2532. /**
  2533. * @param string $idTransazione
  2534. * @return array
  2535. */
  2536. public function returnOrderData($idTransazione) //EARLTP: forse non testata
  2537. {
  2538. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2539.  
  2540. //DATI TRANSAZIONE
  2541. $transazione = TransazioniapplicazioniQuery::create()->filterById($idTransazione)->findOne($con);
  2542.  
  2543. //USERNAME UTENTE PER SICUREZZA
  2544. $username = UtentiQuery::create()->filterByCodportale($transazione->getCodportale())
  2545. ->filterByIdutente($transazione->getFkutente())
  2546. ->select("Username")
  2547. ->findOne($con);
  2548. //DATI ORDINE
  2549. $ordine = OrdinitestataQuery::create()->filterByCodportale($transazione->getCodportale())
  2550. ->filterByCodlaboratorio($transazione->getCodlaboratorio())
  2551. ->filterByUsername($username)
  2552. ->findOne($con);
  2553.  
  2554. $map = null;
  2555.  
  2556. if ($ordine != null) {
  2557. $map["numOrdine"] = $ordine->getNumordine();
  2558. $map["STATUS"] = $ordine->getStato();
  2559. }
  2560.  
  2561. return $map;
  2562.  
  2563. }
  2564.  
  2565. //------------------------------------------------------------------------------------------------------------------
  2566. /* EARLTP: inutile, porting di un metodo java per fototaxi, di fatto sostituito direttamente nella funzione che la
  2567. * invocavavisto che è una riga sola
  2568. * @param string $filePath
  2569. * @return array
  2570. */
  2571. private static function getByteFromFile($filePath)
  2572. {
  2573. return $imgBytes = file($filePath);
  2574. }
  2575.  
  2576. //------------------------------------------------------------------------------------------------------------------
  2577.  
  2578.  
  2579. /*
  2580. * return array
  2581. */
  2582. public function downloadFromRegistraUtente()
  2583. {
  2584. $idSessione = $_REQUEST["jsessionid"];
  2585. if (!empty($idSessione)) {
  2586. try {
  2587. $internalTransaction = true;
  2588. $con = Propel::getConnection(DATASOURCE_NAME);
  2589. $con->beginTransaction();
  2590. $transazione = TransazioniapplicazioniQuery::create()->filterBySessionid($idSessione)->findOne($con);
  2591.  
  2592. $utente = UtentiQuery::create()->filterByUsername($transazione->getUsername())
  2593. ->filterByIdutente($transazione->getFkutente())
  2594. ->findOne($con);
  2595. $cliser = $this->getCliser($utente->getCodportale(), $utente->getUsername(), $utente->getPassword());
  2596.  
  2597. TransazioniapplicazioniQuery::create()->filterById($transazione->getId())->delete($con);
  2598.  
  2599. if ($internalTransaction) {
  2600. $con->commit();
  2601. }
  2602.  
  2603. return $cliser;
  2604. } catch (Exception $e) {
  2605. if ($internalTransaction) {
  2606. $con->rollBack();
  2607. }
  2608. $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
  2609. $this->logger->log(__FILE__, __LINE__, $e->getTraceAsString(), Zend_Log::ERR);
  2610. throw new ServiceException($e->getMessage());
  2611. }
  2612. }
  2613. }
  2614.  
  2615. //------------------------------------------------------------------------------------------------------------------
  2616. /**
  2617. * @param struct $mapParam
  2618. * @return struct
  2619. * @throws Exception
  2620. */
  2621. public function getCliserPacchetto($mapParam)
  2622. {
  2623. $codPortale = $mapParam["codPortale"];
  2624. $codLaboratorio = $mapParam["codLaboratorio"];
  2625. $codFotografo = $mapParam["codFotografo"];
  2626. $tipoUtente = $mapParam["tipoUtente"];
  2627. $legatoFotografo = intval($mapParam["legatoFotografo"]);
  2628.  
  2629. if ($mapParam["codPortale"] == null || $mapParam["codLaboratorio"] == null || $mapParam["tipoUtente"] == null || $mapParam["legatoFotografo"] == null) {
  2630. throw new Exception("Parametri obbligatori mancanti: COD.PORTALE" . $mapParam["codPortale"] . "COD.LABORATORIO" . $mapParam["codLaboratorio"] . " TIPO UTENTE:" . $mapParam["tipoUtente"] . " MODALITA:" . $mapParam["flagModalita"] . " LEGATO FOTOGRAFO:" . $mapParam["legatoFotografo"]);
  2631. //throw new XmlRpcException(WRONG_PARAMETERS, "Parametri obbligatori mancanti: COD.PORTALE" + $mapParam["codPortale"] +"COD.LABORATORIO" + $mapParam["codLaboratorio") +" TIPO UTENTE:" +$mapParam["tipoUtente") + " MODALITA:" + $mapParam["flagModalita") + " LEGATO FOTOGRAFO:"+$mapParam["legatoFotografo"]);
  2632. }
  2633.  
  2634. $codGruppo = $mapParam["codGruppo"] == null ? "" : $mapParam["codGruppo"];
  2635.  
  2636. //----------------------------------------------------
  2637. // CONVERSIONE PORTALE
  2638. //----------------------------------------------------
  2639. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2640. $cp = ConversioneportaliQuery::create()->filterByCodportaleold($codPortale)
  2641. ->filterByCodlaboratorioold('0')
  2642. ->filterByCodfotografoold('0')
  2643. ->filterByCodgruppoold('')
  2644. ->findOne($con);
  2645. $codPortale = $cp != null ? $cp->getCodportalenew() : $codPortale;
  2646. //----------------------------------------------------
  2647.  
  2648. $laboratorio = LaboratoriQuery::create()->filterByCodportale($codPortale)
  2649. ->filterByCodlaboratorio($codLaboratorio)
  2650. ->findOne($con);
  2651.  
  2652. $portale = PortaliQuery::create()->filterByCodportale($codPortale)
  2653. ->findOne($con);
  2654.  
  2655. if ($portale == null) {
  2656. throw new Exception("Portale non esistente: " . $codPortale);
  2657. }
  2658.  
  2659. if ($codFotografo != "") {
  2660. $fotografo = FotografiQuery::create()->filterByCodportale($codPortale)
  2661. ->filterByCodlaboratorio($codLaboratorio)
  2662. ->filterByCodfotografo($codFotografo)
  2663. ->findOne($con);
  2664.  
  2665. $utenteFotografo = UtentiQuery::create()->filterByCodportale($codPortale)
  2666. ->filterByCodlaboratorio($codLaboratorio)
  2667. ->filterByCodfotografo($codFotografo)
  2668. ->filterByFkruolo('3')
  2669. ->findOne($con);
  2670.  
  2671. if ($fotografo == null) {
  2672. $ret = new GetUtenteFotografoResponse();
  2673. return $ret->setStatusMessage(GetUtenteFotografoResponse::STATUS_FOTOGRAFO_NOT_FOUND, array($codPortale, $codLaboratorio, $codLaboratorio));
  2674. }
  2675. }
  2676.  
  2677. //map.put("path_tema", "theme");
  2678. //map.put("tel", "" + utente.getTel());
  2679. //map.put("citta", "" + utente.getCitta());
  2680. //map.put("indirizzo", "" + utente.getIndirizzo());
  2681. //map.put("provincia", "" + utente.getProvincia());
  2682. //map.put("ragione_sociale", "" + utente.getRagioneSociale());
  2683. //map.put("nazione", "" + utente.getNazione());
  2684. //map.put("mail", "" + utente.getMail());
  2685. //map.put("fax", "" + utente.getFax());
  2686. //map.put("piva", "" + utente.getPiva());
  2687. //map.put("cap", "" + utente.getCap());
  2688.  
  2689. $map = new GetCliserPacchettoResponse();
  2690.  
  2691. if ($legatoFotografo == 0) {
  2692. $sitoWeb = $portale->getSitoweb();
  2693. $mailTo = $portale->getMail();
  2694.  
  2695. if ($codGruppo != "") {
  2696. $gruppo = DominigruppiQuery::create()->filterByCodportale($codPortale)
  2697. ->filterByCodgruppo($codGruppo)
  2698. ->findOne($con);
  2699. $sitoWeb = !empty($gruppo) && $gruppo->getDominio() != null && $gruppo->getDominio() != "" ? $gruppo->getDominio() : $sitoWeb;
  2700. }
  2701.  
  2702. $map->setSitoWeb($sitoWeb);
  2703. $map->setMailTo($mailTo);
  2704.  
  2705. } else {
  2706. $map->setSitoWeb($fotografo->getSitoweb());
  2707. $map->setMailTo($fotografo->getMail());
  2708. }
  2709.  
  2710. $map->setCodFotografo($codFotografo);
  2711. $map->setCodLabo($codLaboratorio);
  2712. $map->setUsername("");
  2713. $map->setPassword("");
  2714. $map->setTipo($tipoUtente);
  2715.  
  2716. //ricordarsi dei portali di tipo misto per la consegna
  2717. $consegna = ($tipoUtente == "U" ? $portale->getTipoportale() : "F");
  2718. $map->setConsegna($consegna);
  2719. $map->setTipoPortale($portale->getTipoportale());
  2720. $map->setArtInProp($laboratorio->getArtinpropclient());
  2721.  
  2722. //$map->setMaxOrdine("0");
  2723. //$map->setFidoResiduo("0");
  2724.  
  2725. //$map->setPrimoOrdine(($utente->isPrimoOrdine() ? "1" : "0"));
  2726. $map->setPercScontoPrimoOrdine($portale->getPercscontoprimoordine());
  2727.  
  2728.  
  2729. $map->setImpMinOrdine($portale->getImpminimoordine());
  2730. $map->setQtaMinOrdine($portale->getQtminimaordine());
  2731. //$map->setRagioneSociale("");
  2732.  
  2733. $map->setTimeNextDownload("0");
  2734. $map->setTimeNextDownloadNew($portale->getAggclient());
  2735.  
  2736. if ($laboratorio->getClientcompressionemin() == 0 || $laboratorio->getClientcompressionemax() == 0) {
  2737. $map->setMinQualitySpeed($portale->getClientcompressionemin());
  2738. $map->setMaxQualitySpeed($portale->getClientcompressionemax());
  2739. } else {
  2740. $map->setMinQualitySpeed($laboratorio->getClientcompressionemin());
  2741. $map->setMaxQualitySpeed($laboratorio->getClientcompressionemax());
  2742. }
  2743.  
  2744. $map->setControlloFidoFotografo($portale->getFotografosoggettofido());
  2745.  
  2746. if ($fotografo != null && $utenteFotografo != null) {
  2747. $map->setRifiutoAuto($fotografo->getFlageliminaordini());
  2748.  
  2749. $mappaUtenteFotografo = array(
  2750. "ragioneSociale" => $utenteFotografo->getRagionesociale(),
  2751. "indirizzo" => $utenteFotografo->getIndirizzo(),
  2752. "cap" => $utenteFotografo->getCap(),
  2753. "citta" => $utenteFotografo->getCitta(),
  2754. "provincia" => $utenteFotografo->getProvincia(),
  2755. "nazione" => $utenteFotografo->getNazione(),
  2756. );
  2757.  
  2758. $map->setMappaFotografo($mappaUtenteFotografo);
  2759. }
  2760.  
  2761. //$map["prom_"+ ordine++, mapPromozioni);
  2762.  
  2763. $map->setCodPortale($portale->getCodportale());
  2764.  
  2765. //------------------------
  2766.  
  2767. $map->setModalBrowser($portale->getModalbrowser());
  2768.  
  2769. //------------------------
  2770.  
  2771. $map->setPathUploadPhp("/services/upload_fototaxi.php");
  2772. $map->setUrlServerPhp("/services/xmlrpc.php");
  2773.  
  2774. return $map;
  2775. }
  2776.  
  2777. //------------------------------------------------------------------------------------------------------------------
  2778. /**
  2779. * @param struct $mapParam
  2780. * @return array
  2781. */
  2782. public function getCliserPacchetto2($mapParam)
  2783. {
  2784. $ht = new GetCliserPacchettoResponse();
  2785. $ht = $this->getCliserPacchetto($mapParam);
  2786.  
  2787. $ht->setStatusMessage("0");
  2788. $ht->setMessage("");
  2789. return $ht;
  2790. }
  2791.  
  2792. //------------------------------------------------------------------------------------------------------------------
  2793. // XML LAYOUT
  2794. //---------------------------------------------------------------------------------------------------
  2795. /**
  2796. * @param string $codPortale
  2797. * @param string $codAlbero
  2798. * @return string
  2799. */
  2800. public function getXmlLayout($codPortale, $codAlbero)
  2801. {
  2802. $xml = "";
  2803. //-------------------------------
  2804. // CONVERSIONE PORTALE
  2805. //-------------------------------
  2806. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2807. $cp = ConversioneportaliQuery::create()->filterByCodportaleold($codPortale)
  2808. ->filterByCodlaboratorioold('0')
  2809. ->filterByCodfotografoold('0')
  2810. ->filterByCodgruppoold('')
  2811. ->findOne($con);
  2812. $codPortale = $cp != null ? $cp->getCodportalenew() : $codPortale;
  2813.  
  2814. //----------------------
  2815.  
  2816. $ab = AlberoQuery::create()->filterByCodportale($codPortale)
  2817. ->filterByCodalbero($codAlbero)
  2818. ->findOne($con);
  2819.  
  2820. if ($ab != null) {
  2821. $lb = LayoutQuery::create()->filterByCodarticolo($ab->getCodArticolo())
  2822. ->filterByCodsottoarticolo($ab->getCodSottoarticolo())
  2823. ->findOne($con);
  2824.  
  2825. if ($lb != null) {
  2826. $xml = $lb->getXml() != null ? $lb->getXml() : "";
  2827. }
  2828. }
  2829.  
  2830. return $xml;
  2831. }
  2832.  
  2833. //---------------------------------------------------------------------------------------------------
  2834. // XML SINGOLO LAYOUT
  2835. //---------------------------------------------------------------------------------------------------
  2836. /**
  2837. * @param string $codArticolo
  2838. * @param string $codSottoarticolo
  2839. * @return string
  2840. */
  2841. public function getXmlArticleLayout($codArticolo, $codSottoarticolo){
  2842.  
  2843. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2844.  
  2845. $xml = "";
  2846.  
  2847. $lb = LayoutQuery::create()->filterByCodarticolo($codArticolo)
  2848. ->filterByCodsottoarticolo($codSottoarticolo)
  2849. ->findOne($con);
  2850.  
  2851. if ($lb != null) {
  2852. $xml = $lb->getXml() != null ? $lb->getXml() : "";
  2853. }
  2854.  
  2855. return $xml;
  2856. }
  2857.  
  2858. //------------------------------------------------------------------------------------------------------------------
  2859. // XML MODELLI
  2860. //---------------------------------------------------------------------------------------------------
  2861. /**
  2862. * @param array $classi
  2863. * @return string
  2864. */
  2865. public function getXmlModelli($classi)
  2866. {
  2867. //-- GESTIONE CACHE
  2868. $time_start = microtime(true);
  2869. $config = Zend_Registry::get('Redarea_Configuration');
  2870. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2871.  
  2872. $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
  2873. $xml .= '<MODELLI>';
  2874.  
  2875. //TUTTI I MODELLI DELLE CLASSI RICHIESTE
  2876. $modelli = array();
  2877.  
  2878. foreach ($classi as $classe) {
  2879. //-- GESTIONE CACHE
  2880. $pathFileCache = $config->path->var_labo . "/cache/modelli_classe_" . (string)$classe;
  2881. if (file_exists($pathFileCache)) {
  2882. try {
  2883. $fileContent = file($pathFileCache);
  2884.  
  2885. $xml .= (string)$fileContent[0];
  2886.  
  2887. $this->logger->log(__FILE__, __LINE__, "getXmlModelli CACHE in " . ((microtime(true) - $time_start) / 1000.0) . "secs");
  2888. } catch (Exception $e) {
  2889. print_r($e->getTrace());
  2890. }
  2891. } else {
  2892. //-- GESTIONE CACHE NON PRESENTE
  2893. $modelli = ModelliQuery::create()->filterByClasse($classe)
  2894. ->find($con);
  2895.  
  2896. $xmlClasse = "";
  2897.  
  2898. foreach ($modelli as $modello) {
  2899. if ($modello->getXml() != null && $modello->getXml() != "") {
  2900. $xmlClasse .= $modello->getXml();
  2901. }
  2902. }
  2903.  
  2904. //-- GESTIONE CACHE
  2905. try {
  2906. $handle = fopen($pathFileCache, "w"); //apre/crea file in modalità scrittura, posiziona il puntatore all'inizio
  2907. fwrite($handle, $xmlClasse);
  2908. } catch (Exception $e) {
  2909. print_r($e->getTrace());
  2910. }
  2911.  
  2912. $this->logger->log(__FILE__, __LINE__, "getXmlModelli DATABASE+CACHE in " . ((microtime(true) - $time_start) / 1000.0) . "secs");
  2913.  
  2914. $xml .= $xmlClasse;
  2915. }
  2916. }
  2917.  
  2918. $xml .= '</MODELLI>';
  2919.  
  2920. $this->logger->log(__FILE__, __LINE__, "getXmlModelli processed in " . ((microtime(true) - $time_start) / 1000.0) . "secs");
  2921.  
  2922. return $xml;
  2923. }
  2924.  
  2925. //------------------------------------------------------------------------------------------------------------------
  2926. // XML ALBERO FAMIGLIE
  2927. //---------------------------------------------------------------------------------------------------
  2928. /**
  2929. * @param string $codPortale
  2930. * @param string $codLaboratorio
  2931. * @param string $codServizio
  2932. * @return string
  2933.  
  2934. //RIDEFINITO PER LE VECCHIE VERSIONI
  2935. * public function getXmlAlbero($codPortale, $codLaboratorio, $codServizio)
  2936. * {
  2937. * return $this->getXmlAlbero($codPortale, $codLaboratorio, $codServizio,"U");
  2938. * }*/
  2939.  
  2940. //------------------------------------------------------------------------------------------------------------------
  2941. /**
  2942. * @param string $codPortale
  2943. * @param string $codLaboratorio
  2944. * @param string $codServizio
  2945. * @param string $tipoUtente
  2946. * @return string
  2947.  
  2948. //RIDEFINITO PER LE VECCHIE VERSIONI=> NUOVO PARAMETRO: TIPOUTENTE (U=UTENTE; F=FOTOGRAFO; DEFAULT=UTENTE)
  2949. * public function getXmlAlbero($codPortale, $codLaboratorio, $codServizio, $tipoUtente)
  2950. * {
  2951. * return $this->getXmlAlbero($codPortale, $codLaboratorio, $codServizio, $tipoUtente , 1);
  2952. * }*/
  2953.  
  2954. //------------------------------------------------------------------------------------------------------------------
  2955. /**
  2956. * @param string $codPortale
  2957. * @param string $codLaboratorio
  2958. * @param string $codServizio
  2959. * @param string $tipoUtente
  2960. * @param int $modalita
  2961. * @return string
  2962. */
  2963. //NUOVO PARAMETRO MODALITA ( 0=ENTRAMBE; 1=ONLINE; 2=OFFLINE; DEFAULT=ONLINE )
  2964. public function getXmlAlbero($codPortale, $codLaboratorio, $codServizio, $tipoUtente = "U", $modalita = 1)//valori de default per quelle sopra
  2965. {
  2966. $time_start = microtime(true);
  2967. $config = Zend_Registry::get('Redarea_Configuration');
  2968. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  2969.  
  2970. $pathFileCache = $config->path->var_labo . "/cache/albero_" . $codPortale . "_" . $codLaboratorio . "_" . $codServizio . "_" . $tipoUtente . "_" . $modalita;
  2971.  
  2972. if (file_exists($pathFileCache)) {
  2973. try {
  2974. $fileContent = file($pathFileCache);
  2975. $this->logger->log(__FILE__, __LINE__, "getXmlAlbero processed in " . ((microtime(true) - $time_start) / 1000.0) . "secs");
  2976. return implode($fileContent);
  2977. } catch (Exception $e) {
  2978. var_dump($e->getTrace());
  2979. }
  2980. }
  2981.  
  2982. //-------------------------------------------
  2983. // CONVERSIONE PORTALE
  2984. //-------------------------------------------
  2985. $cp = ConversioneportaliQuery::create()->filterByCodportaleold($codPortale)
  2986. ->filterByCodlaboratorioold('0')
  2987. ->filterByCodfotografoold('0')
  2988. ->filterByCodgruppoold('')
  2989. ->findOne($con);
  2990.  
  2991. if ($cp != null) {
  2992. $this->logger->log(__FILE__, __LINE__, "CONVERSIONE -> Portale Vecchio: " . $codPortale . " Portale Nuovo: " . $cp->getCodportalenew());
  2993. $codPortale = $cp->getCodportalenew();
  2994. }
  2995. //-----------------
  2996.  
  2997. $albero = new Albero();
  2998.  
  2999. //------------------------------------------------------------------------------------------
  3000. // TORNA ALBERO SERVIZIO PER I SOLI ARTICOLI E SOTTOARTICOLI PRESENTI PER LABORATORIO
  3001. //------------------------------------------------------------------------------------------
  3002. $alberoMap = $albero->getAlberoServizio($codPortale, $codLaboratorio, $codServizio, $tipoUtente, $modalita);
  3003.  
  3004. $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
  3005. $xml .= '<FAMIGLIE>';
  3006. $xml .= $albero->getXmlFamiglie($alberoMap);
  3007. $xml .= '</FAMIGLIE>';
  3008.  
  3009. try {
  3010. $handle = fopen($pathFileCache, "w");
  3011. fwrite($handle, $xml);
  3012. } catch (Exception $e) {
  3013. print_r($e->getTrace());
  3014. }
  3015.  
  3016. $this->logger->log(__FILE__, __LINE__, "getXmlAlbero processed in " . ((microtime(true) - $time_start) / 1000.0) . "secs");
  3017.  
  3018. return (string)$xml;
  3019. }
  3020.  
  3021. //------------------------------------------------------------------------------------------------------------------
  3022. // MD5 CLASSI
  3023. //------------------------------------------------------------------------------------------------------------------
  3024. /**
  3025. * @param array $path
  3026. * @param string $type
  3027. * @param string $resolution
  3028. * @return array
  3029.  
  3030. public function getMd5Extension($path, $type, $resolution)
  3031. * {
  3032. * return $this->getMd5Extension($path, $type, $resolution, true);
  3033. * }*/
  3034.  
  3035. /**
  3036. * @param array $path
  3037. * @param string $type
  3038. * @param string $resolution
  3039. * @param bool $calcMd5
  3040. * @return array
  3041. */
  3042. public function getMd5Extension($path, $type, $resolution, $calcMd5 = true)//potrebbe no servire quella sopra così
  3043. {
  3044. $config = Zend_Registry::get('Redarea_Configuration');
  3045.  
  3046. $pathEstensione = $config->path->var_labo . "/SERVIZI/" . strtolower($type);
  3047.  
  3048. $res = strtoupper($resolution) == "H" ? "hres" : "lres";
  3049.  
  3050. $resultMap = array();
  3051.  
  3052. //scorro le classi
  3053. foreach ($path as $dirPath) {
  3054. $pathImages = $pathEstensione . "/" . $dirPath;
  3055.  
  3056. if (strtolower($type) != "font") {
  3057. $pathImages .= "/" . $res;
  3058. }
  3059.  
  3060. if (file_exists($pathImages)) {
  3061. $files = scandir($pathImages);
  3062. unset($files["0"]);
  3063. unset($files["1"]);
  3064.  
  3065. foreach ($files as $file) {
  3066. if (strpos($file, "md5") !== false) //se il nome del file contiene md5 return true(ritorna anche posizione md5)
  3067. {
  3068. continue;
  3069. }
  3070. if ($calcMd5) {
  3071. $md5 = "";
  3072. $nameMd5 = $pathImages . "/" . $file . ".md5";
  3073.  
  3074. if (file_exists($nameMd5)) {
  3075. $md5 = file($nameMd5);
  3076. } else {
  3077. $md5["0"] = md5_file($pathImages . "/" . $file);
  3078. }
  3079.  
  3080. $key = $dirPath . "/" . $file;
  3081.  
  3082. $resultMap[$key] = $md5["0"];
  3083. } else {
  3084. $resultMap = array("/SERVIZI/" . strtolower($type) . "/" . $dirPath . "/" . $file => "");
  3085. }
  3086. }
  3087. } else {
  3088. $this->logger->log(__FILE__, __LINE__, "FILE NOT FOUND" . $pathImages);
  3089. }
  3090. }
  3091.  
  3092. return new Zend_XmlRpc_Value_Struct($resultMap);
  3093. }
  3094.  
  3095. //---------------------------------------------------------------------------------------------------
  3096. // MD5 font
  3097. //---------------------------------------------------------------------------------------------------
  3098. /**
  3099. * @return array
  3100. * @throws Zend_Exception
  3101. */
  3102. public function getMd5Fonts()
  3103. {
  3104.  
  3105. $resultMap = array();
  3106. $config = Zend_Registry::get('Redarea_Configuration');
  3107. $pathFont = $config->path->var_labo . "/SERVIZI/font";
  3108.  
  3109. if (file_exists($pathFont)) {
  3110. $oss = scandir($pathFont);
  3111. unset($oss["0"]);
  3112. unset($oss["1"]);
  3113.  
  3114. foreach ($oss as $os) {
  3115. $pathInOs = $pathFont . "/" . $os;
  3116. if (file_exists($pathInOs)) {
  3117. $filesFont = scandir($pathInOs);
  3118. unset($filesFont["0"]);
  3119. unset($filesFont["1"]);
  3120.  
  3121. foreach ($filesFont as $fileFont) {
  3122. if (strpos($fileFont, "md5") !== false) //se il nome del file contiene md5 return true(ritorna anche posizione md5)
  3123. {
  3124. continue;
  3125. }
  3126.  
  3127. $md5 = "";
  3128. $md5Font = $pathInOs . "/" . $fileFont . ".md5";
  3129.  
  3130. if (file_exists($md5Font)) {
  3131. $md5 = file($md5Font);
  3132. } else {
  3133. $md5["0"] = md5_file($pathInOs . "/" . $fileFont);
  3134. }
  3135.  
  3136. $key = $os . "/" . $fileFont;
  3137.  
  3138. $resultMap[$key] = $md5["0"];
  3139. }
  3140. }
  3141. }
  3142. } else {
  3143. $this->logger->log(__FILE__, __LINE__, "FILE NOT FOUND" . $pathFont);
  3144. }
  3145.  
  3146. return $resultMap;
  3147. }
  3148.  
  3149. //---------------------------------------------------------------------------------------------------
  3150. // MD5 CLASSI ALL
  3151. //---------------------------------------------------------------------------------------------------
  3152. /**
  3153. * @param string $type
  3154. * @param string $resolution
  3155. * @return array
  3156. */
  3157. public function getAllMd5Extension($type, $resolution)
  3158. {
  3159. $config = Zend_Registry::get('Redarea_Configuration');
  3160. $pathEstensione = $config->path->var_labo . "/SERVIZI/" . strtolower($type);
  3161. $res = strtoupper($resolution) == "H" ? "hres" : "lres";
  3162.  
  3163. $resultMap = array();
  3164.  
  3165. if (file_exists($pathEstensione)) {
  3166. $alls = scandir($pathEstensione);
  3167. unset($alls["0"]);
  3168. unset($alls["1"]);
  3169.  
  3170. foreach ($alls as $all) {
  3171. $classe = $pathEstensione . "/" . $all;
  3172.  
  3173. if (strtolower($type) != "font") {
  3174. $classe .= "/" . $res;
  3175. }
  3176.  
  3177. if (file_exists($classe)) {
  3178. $files = scandir($classe);
  3179. unset($files["0"]);
  3180. unset($files["1"]);
  3181.  
  3182. foreach ($files as $file) {
  3183. if (strpos($file, "md5") !== false) //se il nome del file contiene md5 return true(ritorna anche posizione md5)
  3184. {
  3185. continue;
  3186. }
  3187.  
  3188. $md5 = "";
  3189.  
  3190. $md5Path = $classe . "/" . $file . ".md5";
  3191. if (file_exists($md5Path)) {
  3192. $md5 = file($md5Path);
  3193. } else {
  3194. $md5["0"] = md5_file($classe . "/" . $file);
  3195. }
  3196.  
  3197. $key = $all . "/" . $file;
  3198.  
  3199. $resultMap[$key] = $md5["0"];
  3200. }
  3201. }
  3202.  
  3203. if (!file_exists($pathEstensione)) {
  3204. $this->logger->log(__FILE__, __LINE__, "FILE NOT FOUND" . $pathEstensione);
  3205. }
  3206. }
  3207. }
  3208.  
  3209. return $resultMap;
  3210. }
  3211.  
  3212. //---------------------------------------------------------------------------------------
  3213. // CONTROLLO ORDINE PER SALVA CON NOME
  3214. //---------------------------------------------------------------------------------------
  3215. /**
  3216. * @param struct $oggetti
  3217. * @param struct $params
  3218. * @return array
  3219. * @throws Exception
  3220. */
  3221. public function checkOrdine($oggetti, $params)
  3222. {
  3223. try {
  3224. $resultMap = array();
  3225. $oggettiMap = array();
  3226. //errorsMap viene inizializzato con un key/value per forzare la conversione in python a dictionary
  3227. $errorsMap = array("fakeKey" => "fakeValue");
  3228. $config = Zend_Registry::get('Redarea_Configuration');
  3229. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  3230.  
  3231. //----------------------------------------------------------------------------------------
  3232. // CONTROLLO OGGETTI
  3233. //----------------------------------------------------------------------------------------
  3234.  
  3235. foreach (array_keys($oggetti) as $oggetto) {
  3236.  
  3237. $path = (string)$oggetto;
  3238.  
  3239. //GESTIONE PATH PER WINDOWS
  3240. $pathArray = strpos($path, "\\") ? explode("\\", $path) : explode("/", $path);
  3241. $isFont = false;
  3242.  
  3243. if (strtolower($pathArray["0"]) == "font") {
  3244. $newPath = strtolower($pathArray["0"]) . "/" . $pathArray["1"] . "/" . $pathArray["2"];
  3245. $isFont = true;
  3246. } else {
  3247. $newPath = strtolower($pathArray["0"]) . "/" . $pathArray["1"] . "/lres/" . $pathArray["2"];
  3248. }
  3249.  
  3250. $pathFile = $config->path->var_labo . "/SERVIZI/" . $newPath;
  3251.  
  3252. //PER I FONT NON OCCORRE CONTROLLARE L'MD5
  3253. if ($isFont) {
  3254. if (!file_exists($pathFile)) {
  3255. $oggettiMap[$path] = "0";
  3256. }
  3257. } else {
  3258. $md5client = (string)$oggetti[$oggetto];
  3259.  
  3260. if (file_exists($pathFile)) {
  3261. $md5 = md5_file($pathFile);
  3262.  
  3263. if ($md5client != $md5) {
  3264. $oggettiMap[$path] = $md5;
  3265. }
  3266. } else {
  3267. $oggettiMap[$path] = "0";
  3268. }
  3269. }
  3270. }
  3271.  
  3272. $resultMap["mappa oggetti"] = $oggettiMap;
  3273.  
  3274. //----------------------------------------------------------------------------------------
  3275. // CONTROLLO ORDINE
  3276. //----------------------------------------------------------------------------------------
  3277.  
  3278. //-----------------------------------
  3279. // PARAMETRI OBBLIGATORI
  3280. //-----------------------------------
  3281. if ($params["username"] == null || $params["password"] == null || $params["codPortale"] == null ||
  3282. $params["codArticolo"] == null || $params["quantita"] == null || $params["prezzoArticolo"] == null ||
  3283. $params["tipoPagamento"] == null || $params["totaleOrdine"] == null
  3284. ) {
  3285. $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Parametri obbligatori mancanti");
  3286. $resultMap["mappa errori"] = $errorsMap;
  3287. return $resultMap;
  3288. }
  3289.  
  3290. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE:CONTROLLO PARAMETRI OBBLIGATORI OK");
  3291.  
  3292. //----------------------------------------
  3293. // LOGIN UTENTE
  3294. //----------------------------------------
  3295. $loginStatus = $this->login((string)$params["codPortale"], (string)$params["username"], (string)$params["password"], false);
  3296. if ($loginStatus > 0) {
  3297. $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Login utente fallito");
  3298. $resultMap["mappa errori"] = $errorsMap;
  3299. return $resultMap;
  3300. }
  3301.  
  3302. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE:LOGIN UTENTE OK");
  3303.  
  3304. //------------------------------------------
  3305. // DATI
  3306. //------------------------------------------
  3307. $utente = UtentiQuery::create()->filterByCodportale($params["codPortale"])
  3308. ->filterByUsername($params["username"])
  3309. ->findOne($con);
  3310. if ($utente == null) {
  3311. $utente = UtentiQuery::create()->filterByCodportaleold($params["codPortale"])
  3312. ->filterByUsername($params["username"])
  3313. ->findOne($con);
  3314. }
  3315.  
  3316. $portale = PortaliQuery::create()->filterByCodportale($utente->getCodportale())
  3317. ->findOne($con);
  3318.  
  3319. $fotografo = FotografiQuery::create()->filterByCodportale($utente->getCodportale())
  3320. ->filterByCodlaboratorio($utente->getCodLaboratorio())
  3321. ->filterByCodfotografo($utente->getCodFotografo())
  3322. ->findOne($con);
  3323.  
  3324. if ($portale == null) {
  3325. throw new Exception("Portale non esistente: " . $params["codPortale"]);
  3326. }
  3327.  
  3328. if ($fotografo == null) {
  3329. throw new Exception("Fotografo non esistente per portale: " . $utente->getCodportale() . " username: " . $utente->getUsername());
  3330. }
  3331.  
  3332. //------------------------------------------
  3333.  
  3334. $language = $portale->getLingua() . '_' . strtoupper($portale->getLingua());
  3335. $translator = new Zend_Translate('Ini', APPLICATION_PATH . '/languages/lang.' . $language . '.ini', $language);
  3336.  
  3337. //------------------------------------------
  3338.  
  3339. $totaleOrdine = $params["totaleOrdine"];
  3340. $prezzoTransfertToCheck = 0;
  3341.  
  3342. //------------------------------------------------
  3343. // CONTROLLO ESISTENZA ARTICOLO PER LABORATORIO
  3344. //------------------------------------------------
  3345. $articolo = ArticoliQuery::create()->filterByCodportale($utente->getCodportale())
  3346. ->filterByCodlaboratorio($utente->getCodLaboratorio())
  3347. ->filterByCodarticolo($params["codArticolo"])
  3348. ->findOne($con);
  3349.  
  3350. if ($articolo == null) {
  3351. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_articolo")));
  3352. $resultMap["mappa errori"] = $errorsMap;
  3353. return $resultMap;
  3354. } else {
  3355.  
  3356. $articolo->setArticoloTransfert($fotografo, $utente->getLegatoFotografo(), $utente->getTipo());
  3357.  
  3358. if($articolo->getArticoloTransfert() != null) {
  3359. $prezzoTransfertToCheck = $articolo->getArticoloTransfert()->getListino() !=null ? $articolo->getArticoloTransfert()->getListino()->getPrezzo1() : $prezzoTransfertToCheck;
  3360. }
  3361.  
  3362. $listino = $this->getListino($articolo, $utente, $fotografo);
  3363.  
  3364. if($listino != null) {
  3365. $articolo->setListino($listino);
  3366. }else{
  3367. throw new Exception("Listino non presente per portale: " . $utente->getCodPortale() . " username: " . $utente->getUsername() . " password: " . $utente->getPassword() . " articolo: " . $articolo->getCodArticolo());
  3368. }
  3369.  
  3370. }
  3371.  
  3372. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: ARTICOLO PRESENTE PER LABORATORIO " . $articolo->getCodArticolo());
  3373.  
  3374. //-----------------------------------------
  3375. // CONTROLLO ESISTENZA PAGINA AGGIUNTIVA
  3376. //-----------------------------------------
  3377.  
  3378. $paginaAggiuntiva = null;
  3379. $numPagineAggiuntive = 0;
  3380. $prezzoPaginaAggiuntiva = 0;
  3381.  
  3382. if (!empty($params["codPaginaAggiuntiva"])) {
  3383. $paginaAggiuntiva = ArticoliQuery::create()->filterByCodportale($utente->getCodPortale())
  3384. ->filterByCodlaboratorio($utente->getCodlaboratorio())
  3385. ->filterByCodarticolo($params["codPaginaAggiuntiva"])
  3386. ->findOne($con);
  3387.  
  3388. if ($paginaAggiuntiva == null) {
  3389. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_pag_agg")));
  3390. $resultMap["mappa errori"] = $errorsMap;
  3391. return $resultMap;
  3392. }
  3393.  
  3394. //PARAMETRO NUM PAGINE AGGIUNTIVE MANCANTE
  3395. if ($params["numPagineAggiuntive"] == null) {
  3396. $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Parametro numPagineAggiuntive non settato");
  3397. $resultMap["mappa errori"] = $errorsMap;
  3398. return $resultMap;
  3399. }
  3400.  
  3401. $numPagineAggiuntive = intval($params["numPagineAggiuntive"]);
  3402.  
  3403. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: PAGINA AGGIUNTIVA " . $paginaAggiuntiva->getCodarticolo());
  3404.  
  3405. //---------------------------------------
  3406. // SCAGLIONE PREZZO PAGINA AGGIUNTIVA
  3407. //---------------------------------------
  3408. $listinoPa = $this->getListino($paginaAggiuntiva, $utente, $fotografo);
  3409.  
  3410. if(!empty($listinoPa)) {
  3411.  
  3412. $prezzoPaginaAggiuntiva = $listinoPa->getPrezzo(intval($params["numPagineAggiuntive"]));
  3413.  
  3414. if((Double)$params["prezzoPaginaAggiuntiva"] != $prezzoPaginaAggiuntiva) {
  3415.  
  3416. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1",sprintf($translator->_("check.ordine.msg_err_pag_agg_prezzo")));
  3417.  
  3418. }
  3419.  
  3420. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: PREZZO PAGINA AGGIUNTIVA " . $prezzoPaginaAggiuntiva);
  3421.  
  3422. $totaleOrdine += $prezzoPaginaAggiuntiva * $numPagineAggiuntive;
  3423. } else {
  3424. throw new Exception("Listino Pagina Aggiuntiva non presente per portale: " . $utente->getCodportale() . " username: " . $utente->getUsername() . " password: " . $utente->getPassword() . " articolo: " . $paginaAggiuntiva->getCodarticolo());
  3425. }
  3426.  
  3427. }
  3428.  
  3429. //--------------------------------------------
  3430. // SCAGLIONE PREZZO ARTICOLO
  3431. //--------------------------------------------
  3432. try {
  3433. $quantita = intval($params["quantita"]);
  3434. } catch (Exception $e) {
  3435. $this->logger->log(__FILE__, __LINE__, $e->getTraceAsString());
  3436. //addMsgToErrorMap(errorsMap,"1","La quantita contiene un valore non valido");
  3437. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_quantita")));
  3438. $resultMap["mappa errori"] = $errorsMap;
  3439. return $resultMap;
  3440.  
  3441. }
  3442.  
  3443. $prezzoArticolo = $articolo->getListino()->getPrezzo($quantita);
  3444.  
  3445. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: PREZZO ARTICOLO " . $prezzoArticolo);
  3446.  
  3447. if (floatval($params["prezzoArticolo"]) != $prezzoArticolo) {
  3448. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_articolo_prezzo")));
  3449. }
  3450.  
  3451. //totaleOrdine += prezzoArticolo * (Integer.parseInt(params.get("quantita").toString()) );
  3452.  
  3453. //--------------------------------------------
  3454. // TRANSFERT
  3455. //--------------------------------------------
  3456. if (!empty($params["flagTransfert"]) && (string)$params["flagTransfert"] == "1") {
  3457.  
  3458. $transfert = $articolo->getArticoloTransfert();
  3459.  
  3460. if (!empty($transfert)) {
  3461.  
  3462. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CODICE TRANSFERT " . $transfert->getCodArticolo());
  3463.  
  3464. $listinoTransfert = $this->getListino($transfert, $utente, $fotografo);
  3465.  
  3466. if (!empty($listinoTransfert)) {
  3467.  
  3468. $prezzoTransfert = $listinoTransfert->getPrezzo1();
  3469. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: PREZZO TRANSFERT " . $prezzoTransfert);
  3470.  
  3471. //PARAMETRO PREZZO TRANSFERT MANCANTE
  3472. if (empty($params["prezzoTransfert"])) {
  3473. $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Parametro prezzo transfert mancante");
  3474. $resultMap["mappa errori"] = $errorsMap;
  3475. return $resultMap;
  3476. }
  3477.  
  3478. if ($prezzoTransfert != floatval((string)$params["prezzoTransfert"])) {
  3479. //addMsgToErrorMap(errorsMap,"1","Alcune delle voci di costo che compongono il totale ordine sono variate");
  3480. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_totale")));
  3481. }
  3482.  
  3483. } else {
  3484. throw new Exception("Listino Transfert non presente per portale: " . $utente->getCodPortale() . " username: " . $utente->getUsername() . " password: " . $utente->getPassword() . " articolo: " . $transfert->getCodArticolo());
  3485. }
  3486. } else {
  3487. //addMsgToErrorMap(errorsMap,"1","Alcune delle voci di costo che compongono il totale ordine sono variate");
  3488. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_totale")));
  3489. }
  3490. }
  3491.  
  3492. //$this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: TOTALE NON SCONTATO " . totaleOrdine);
  3493.  
  3494. $checkTotale = true;
  3495.  
  3496. //------------------------------------------------------------
  3497. // SE IL FOTOGRAFO FORZA IL TOTALE NON FACCIO IL CONTROLLO
  3498. //------------------------------------------------------------
  3499. if ($params["totale_forzato"] != null && intval($params["totale_forzato"]) == 1) {
  3500. $checkTotale = false;
  3501. }
  3502.  
  3503. if ($checkTotale) {
  3504. $cartService = new Cart_Service();
  3505. $projectService = new Projects_Service();
  3506. $accountService = new Account_Service();
  3507. $id_prefix = $config->db->id->prefix;
  3508. try {
  3509. $internalTransaction = true;
  3510. $conT = Propel::getConnection(DATASOURCE_NAME);
  3511. $conT->beginTransaction();
  3512.  
  3513. $idProgetto = $projectService->inizializeProject($utente->getIdutente(), "fototaxi_xmr", $utente->getIdutente() . uniqid(), null, null, $conT, null);
  3514.  
  3515. $xml = "<?xml version='1.0' encoding='iso-8859-15'?><PAGES><QT>" . $params["quantita"] . "</QT><CODE_ARTICOLO>" . $params["codArticolo"] . "</CODE_ARTICOLO>";
  3516.  
  3517. if (!empty($params["codPaginaAggiuntiva"])) {
  3518. $xml .= "<CODE_PAG_AGG>" . $params["codPaginaAggiuntiva"] . "</CODE_PAG_AGG><QT_PAG_AGG>" . $params["numPagineAggiuntive"] . "</QT_PAG_AGG>";
  3519. }
  3520. $xml .= "</PAGES>";
  3521. ProgettiQuery::create()->filterByIdprogetto($idProgetto)->update(array("Xml" => $xml), $conT);
  3522.  
  3523. $transactionId = $id_prefix . uniqid();
  3524. $transazione = new Transazioniapplicazioni();
  3525. $transazione->setId($transactionId);
  3526. $transazione->setCodportale($utente->getCodportale());
  3527. $transazione->setCodlaboratorio($utente->getCodlaboratorio());
  3528. $transazione->setCodfotografo($utente->getCodfotografo());
  3529. //$transazione->setCodgruppo();
  3530. //$transazione->setCodagente($utente->getCodagente());
  3531. $transazione->setUsername($utente->getUsername());
  3532. $transazione->setFkutente($utente->getIdutente());
  3533. $transazione->setDatainserimento(date("Y-m-d H:i:s"));
  3534. $transazione->setFkprogetto($idProgetto);
  3535. $transazione->setClient("FOTOTAXI-OLD");
  3536. $transazione->save($conT);
  3537.  
  3538. //LOGIN PER ATTIVARE PROMO
  3539. $accountService->loginByUserId($transazione->getFkutente(), $portale->getSitoweb());
  3540.  
  3541. $cartID = $cartService->addProject($utente->getIdutente(), $idProgetto, null, $conT, $transactionId, false);
  3542.  
  3543. if ($internalTransaction) {
  3544. $conT->commit();
  3545. }
  3546. } catch (Exception $e) {
  3547. if ($internalTransaction) {
  3548. $conT->rollBack();
  3549. }
  3550. $this->logger->log(__FILE__, __LINE__, $e, Zend_Log::ERR);
  3551. }
  3552.  
  3553. if (empty($cartID)) {
  3554. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", "CARRELLO NON CREATO");
  3555. } else {
  3556. //--Rut - 07/10/2015 - passaggio client al carrello
  3557. $cart = $cartService->getCart($utente->getIdutente(), $cartID, $transactionId, 0.0, false, null, false, false, 'FOTOTAXI');
  3558. $totaleCart = $cart["2"];
  3559. $totSpese = 0;
  3560.  
  3561. //-------------------------------------------------
  3562. // PROMOZIONE
  3563. //-------------------------------------------------
  3564.  
  3565. $qtaOrdinate = 0;
  3566. $qtaResidue = 0;
  3567. $qtaPromo = 0;
  3568.  
  3569. $valoreResiduo = 0;
  3570. $totalePromo = 0;
  3571. $scontaTransfert = false;
  3572.  
  3573. $currentPromo = null;
  3574.  
  3575. /******************************************************
  3576. * GESTIONE CAMPAGNE APR 2012
  3577. *****************************************************/
  3578. $now = new DateTime();
  3579. $campagne = CampagneQuery::create() ->filterByCodiceportale($utente->getCodportale())
  3580. ->filterByDatainizio(array('max' => $now))
  3581. ->filterByDatafine(array('min' => $now))
  3582. ->filterByTipo(array('ALL'), Criteria::IN)
  3583. ->find($con);
  3584. $listiniCampagneMap = array();
  3585. if(count($campagne) > 0 ) {
  3586. foreach($campagne as $campagna) {
  3587. $escluso = EsclusionefotograficampagneQuery::create()
  3588. ->filterByCodportale($utente->getcodPortale())
  3589. ->filterByCodlaboratorio($utente->getCodlaboratorio())
  3590. ->filterByCodfotografo($utente->getCodfotografo())
  3591. ->where("Esclusionefotograficampagne.Codcampagna = ?",
  3592. $campagna->getCodicecampagna())
  3593. ->orWhere("EsclusioneFotografiCampagne.Codcampagna = ''")
  3594. ->findOne($con);
  3595.  
  3596. if (empty($escluso) &&
  3597. $campagna->isApplicabileUtente($utente) &&
  3598. $campagna->getCheckTemi() == 0 &&
  3599. $campagna->isApplicabileClient('FOTOTAXIOLD') &&
  3600. $campagna->isApplicabileFotografo($utente)
  3601. ) {
  3602. $listiniCampagna = $campagna->getListinoPromozionale();
  3603. foreach ($listiniCampagna as $listinoCampagna) {
  3604. $listiniCampagneMap[$listinoCampagna->getCodicearticolo()] = $listinoCampagna;
  3605. }
  3606. }
  3607. }
  3608. }
  3609.  
  3610. $promozioneCampagna = "";
  3611. if (count($listiniCampagneMap) > 0) {
  3612. //TODO EARLTP: vedere bene questo punto
  3613. // c'e' un listino promozionale su uno degli articoli ordinati o sulla pagina aggiuntiva
  3614. if (
  3615. (array_key_exists($listiniCampagneMap, $articolo->getCodArticolo())) ||
  3616. (!empty($params["applica_pag_agg"]) && !empty($paginaAggiuntiva) && array_key_exists($listiniCampagneMap, $paginaAggiuntiva->getCodArticolo()))
  3617. ) {
  3618. if (array_key_exists($listiniCampagneMap, $articolo->getCodArticolo())) {
  3619. $listinoPromo = $listiniCampagneMap[$articolo->getCodArticolo()];
  3620. $scontato = $listinoPromo->getPrezzo($quantita) * $quantita;
  3621. $totalePromo += ($prezzoArticolo * $quantita) - $scontato;
  3622. $promozioneCampagna = $listinoPromo->getCodicePromozione();
  3623. }
  3624.  
  3625. if (!empty($params["applica_pag_agg"]) && !empty($paginaAggiuntiva) && array_key_exists($listiniCampagneMap, $paginaAggiuntiva->getCodArticolo())) {
  3626.  
  3627. $listinoPromo = $listiniCampagneMap[$paginaAggiuntiva->getCodArticolo()];
  3628.  
  3629. $scontato = $listinoPromo->getPrezzo($numPagineAggiuntive) * $numPagineAggiuntive;
  3630. $totalePromo += ($prezzoPaginaAggiuntiva * $numPagineAggiuntive) - $scontato;
  3631. $promozioneCampagna = $promozioneCampagna == "" ? $listinoPromo->getCodicePromozione() : $promozioneCampagna;
  3632. }
  3633.  
  3634. //sul client non e' stata applicata la promozione campagna: vanno riscaricati il cliser e i listini promozionali
  3635. if (empty($params["codPromozione"])) {
  3636. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CAMPAGNA PROMOZIONALE NON APPLICATA ");
  3637. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", "I prezzi devono essere aggiornati"); //todo: sostituire messaggio
  3638. }
  3639. /* commentato: da quando e' stata introdotta la priorita sulle promo non ha più senso poiche l'utente potrebbe
  3640. avere una promo che ha priorita sulla campagna
  3641. */
  3642. //sul client e' stata applicata una promozione diversa da quella della campagna: vanno riscaricati il cliser e i listini promozionali
  3643. /*else if( params.get("codPromozione") != null && !params.get("codPromozione").equals(promozioneCampagna) ){
  3644.  
  3645. addMsgToErrorMap(errorsMap,"1","promozione applicata non valida"); //todo:cambiare messaggio errore e verificare se deve andare avanti con i controlli oppure no
  3646.  
  3647. }*/
  3648. }
  3649.  
  3650. }
  3651. /** FINE **/
  3652.  
  3653. if (!empty($params["codPromozione"])) {
  3654.  
  3655. if (empty($params["importoPromozione"])) {
  3656. $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Importo promozione non settato");
  3657. $resultMap["mappa errori"] = $errorsMap;
  3658. return $resultMap;
  3659. }
  3660.  
  3661. $promozione = PromozioniQuery::create()->filterByCodportale($utente->getCodportale())->filterByCodpromozione($params["codPromozione"])->findOne($con);
  3662.  
  3663.  
  3664. //==================================
  3665. // PROMOZIONE INESISTENTE O SCADUTA
  3666. //==================================
  3667. $promozioneScaduta = false;
  3668. if(!empty($promozione)){
  3669. //TODO EARLTP: verifica che funziona
  3670. $now = strtotime('now');
  3671. $scadenza = strtotime($promozione->getDatascadenza());
  3672. $promozioneScaduta = $now > $scadenza;
  3673. /*Calendar now = new GregorianCalendar();
  3674.  
  3675. now.set(Calendar.HOUR_OF_DAY, 0);
  3676. now.set(Calendar.MINUTE, 0);
  3677. now.set(Calendar.SECOND, 0);
  3678. now.set(Calendar.MILLISECOND, 0);
  3679.  
  3680. Calendar scadenza = new GregorianCalendar();
  3681. scadenza.setTimeInMillis(promozione.getDataScadenza().getTime());
  3682.  
  3683. promozioneScaduta = now.after(scadenza);*/
  3684.  
  3685. }
  3686.  
  3687. // verifica applicabilita condizioni: qta minima ordine o importo minimo ordine e classe articoli/lista articoli
  3688. $isApplicabile = true;
  3689. //TODO EARLTP: ho già il carrello
  3690. $cartItems = $cart[1][0]["items"];
  3691. /*List cartItems = new ArrayList();
  3692.  
  3693. OrdineCarrelloBean ocb = new OrdineCarrelloBean();
  3694. ocb.setArticolo(articolo);
  3695. ocb.setQuantita(quantita);
  3696. ocb.setPrezzo(prezzoArticolo);
  3697.  
  3698. cartItems.add(ocb);
  3699.  
  3700. if( paginaAggiuntiva != null ){
  3701. OrdineCarrelloBean ocb2 = new OrdineCarrelloBean();
  3702. ocb2.setArticolo(paginaAggiuntiva);
  3703. ocb2.setQuantita(numPagineAggiuntive);
  3704. ocb2.setPrezzo(prezzoPaginaAggiuntiva);
  3705.  
  3706. cartItems.add(ocb2);
  3707. }*/
  3708.  
  3709. $credits = !empty($promozione) ? CreditsQuery::create()->filterByCodportale($utente->getCodportale())->filterByCodpromozione($promozione->getCodpromozione())->filterByUsername($utente->getUsername())->filterByUtilizzabile('1')->findOne($con) : array();
  3710.  
  3711. if (!empty($promozione) && ($promozione->getQtaminimaordine() > 0 || $promozione->getImpminimoordine() > 0)) {
  3712. $isApplicabile = $this->verificaApplicabilitaCondizioni($cartItems, $promozione, $credits, $params["applica_pag_agg"] != null);
  3713. }
  3714.  
  3715. if (empty($promozione) || $promozioneScaduta || !$isApplicabile) {
  3716. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_promo_no_attiva")));
  3717. } else {
  3718. //==================================
  3719. // PROMOZIONE NON APPLICABILE
  3720. //==================================
  3721. if ($promozione->getPrimoordine() == 1 && !$utente->isPrimoOrdine()) {
  3722. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_promo_primo_ordine")));
  3723. } else {
  3724. $currentPromo = $promozione;
  3725.  
  3726. //========================================
  3727. // CREDITS NON DISPONIBILI PER PROMOZIONE
  3728. //========================================
  3729. if (count($credits) == 0 && empty($promozioneCampagna)) {
  3730. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_promo_usata")));
  3731. } else {
  3732. $flagApplicaCampagna = false;
  3733.  
  3734. if (!empty($promozioneCampagna)) {
  3735. $promoCampagna = PromozioniQuery::create()->filterByCodportale($utente->getCodportale())->filterByCodpromozione($promozioneCampagna)->findOne($con);
  3736. $flagApplicaCampagna = $promoCampagna->getPriorita() < $promozione->getPriorita();
  3737. }
  3738.  
  3739.  
  3740. if (!$flagApplicaCampagna) {
  3741.  
  3742. $promozione->generaItemsPromozione()
  3743.  
  3744. if ($promozione->getFlagtipopromozione() == 0) {
  3745.  
  3746. // qta omaggio
  3747. if ($promozione->getPercsconto() == 0) {
  3748. $result = $this->calcolaScontoQtaOmaggio($cartItems, $promozione, $credits, $params["applica_pag_agg"] != null, 0);
  3749. $totalePromo = (Double)$result["totaleSconto"];
  3750. $scontaTransfert = (Boolean)$result["scontaTransfert"];
  3751. } // 3x2
  3752. else {
  3753. $totalePromo = $this->calcolaSconto3x2($cartItems, $promozione, $params["applica_pag_agg"] != null);
  3754. }
  3755. } // percentuale di sconto
  3756. elseif ($promozione->getFlagtipopromozione() == 1) {
  3757. $totalePromo = $this->calcolaScontoPercentuale($cartItems, $promozione, $params["applica_pag_agg"] != null);
  3758. } // prepagata
  3759. elseif ($promozione->getFlagtipopromozione() == 2) {
  3760.  
  3761. $speseSped = (Double)$params["totaleSpeseSpedizione"];
  3762. $tot = $totaleOrdine + $prezzoTransfert + $speseSped;
  3763. $totalePromo = $this->calcolaScontoPrepagata($credits, $promozione, $tot);
  3764.  
  3765. if ($totalePromo > 0 && $promozione->getPagatransfert() == 0) {
  3766. $prezzoTransfert = 0;
  3767. }
  3768. } // a prezzo fisso
  3769. elseif ($promozione->getFlagtipopromozione() == 4) {
  3770. $totalePromo = $this->calcolaScontoPrezzoFisso($cartItems, $promozione, $params["applica_pag_agg"] != null);
  3771. } // a valore
  3772. elseif ($promozione->getFlagtipopromozione() == 5) {
  3773.  
  3774. $totalePromo = $this->calcolaScontoValore($cartItems, $promozione, $credits, $params["applica_pag_agg"] != null);
  3775.  
  3776. } // kit
  3777. elseif ($promozione->getFlagtipopromozione() == 6) {
  3778. $totalePromo = $this->calcolaScontoKit($cartItems, $promozione, $credits, $params["applica_pag_agg"] != null, 0);
  3779. }
  3780. }
  3781. }
  3782. }
  3783. }
  3784.  
  3785. if ($totaleOrdine > $promozione->getImpminimoordine()) {
  3786.  
  3787. if ($promozione->getPagatransfert() == 0 && $promozione->getFlagtipopromozione() != 2 && $scontaTransfert) {
  3788. $prezzoTransfert = 0;
  3789. }
  3790. } else {
  3791. $totalePromo = 0;
  3792. }
  3793.  
  3794. $totalePromo = (float)($totalePromo + 0.005);
  3795. $totalePromoClient = (Double)$params["importoPromozione"];
  3796. $totalePromoClient = (float)($totalePromoClient + 0.005);
  3797.  
  3798. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: TOTALE PROMOZIONE SERVER " . $totalePromo);
  3799. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: TOTALE PROMOZIONE CLIENT " . $totalePromoClient);
  3800.  
  3801. if ($totalePromoClient != $totalePromo) {
  3802. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_promo_importo")));
  3803. }
  3804. }
  3805.  
  3806. $totaleOrdine = $totaleOrdine - $totalePromo + $prezzoTransfert;
  3807.  
  3808. if (!empty($currentPromo) && $currentPromo->getFlagtipopromozione() == 2 && $totalePromo > 0) {
  3809. $totaleOrdine = 0;
  3810. }
  3811.  
  3812. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: TOTALE SCONTATO " . $totaleOrdine);
  3813.  
  3814. //-------------------------------------------------------------------------
  3815. // TIPO PAGAMENTO
  3816. //-------------------------------------------------------------------------
  3817.  
  3818. //FIDO
  3819. if ($params["tipoPagamento"] == "0") {
  3820. //controllo fido residuo solo se flag elimina ordini = si => Pytaxi impedisce l'invio dell'ordine se questo supera il fido
  3821. if ($fotografo->getFlageliminaordini() == 1 && ($utente->getFkruolo() != "3" || ($utente->getFkruolo() == "3" && $portale->getFotografosoggettofido() == 1))) {
  3822. $fidoResiduo = $accountService->getFidoResiduo($utente->getIdutente());
  3823. if ($totaleOrdine > $fidoResiduo) {
  3824. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_fido")));
  3825. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CONTROLLO FIDO RESIDUO-> FIDO RESIDUO UTENTE " . $fidoResiduo);
  3826. }
  3827.  
  3828. $maxOrdineUtente = ($utente->getMaxordineautomatico() == 0) ? $fotografo->getMaxordineautomatico() : $utente->getMaxordineautomatico();
  3829.  
  3830. if ($totaleOrdine > $maxOrdineUtente) {
  3831. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_max_ordine")));
  3832. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CONTROLLO FIDO RESIDUO-> MAX ORDINE UTENTE " . $maxOrdineUtente);
  3833. }
  3834. }
  3835. } else {
  3836. if ($params["tipoSpedizione"] == null || $params["totaleSpeseSpedizione"] == null) {
  3837. $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Parametri tipoSpedizione e totaleSpeseSpedizione non settati");
  3838. $resultMap["mappa errori"] = $errorsMap;
  3839. return $resultMap;
  3840. } else {
  3841. $mpb = ModpagamentoQuery::create()->filterByCodportale($utente->getCodPortale())
  3842. ->filterByCodmodalita($params["tipoPagamento"])
  3843. ->findOne($con);
  3844. if ($mpb == null) {
  3845. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_mod_pag")));
  3846. }
  3847.  
  3848. $tsb = TipospedizioneQuery::create()->filterByCodportale($utente->getCodPortale())
  3849. ->filterByCodspedizione($params["tipoSpedizione"])
  3850. ->findOne($con);
  3851. if ($tsb == null) {
  3852. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_tipo_sped")));
  3853. }
  3854.  
  3855. if ($mpb != null && $tsb != null) {
  3856. $peso = $articolo->getGrammi() * (intval($params["quantita"]));
  3857.  
  3858. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CONTROLLO SPESE SPEDIZIONE-> PESO " . $peso);
  3859.  
  3860. $ssb = SpesespedizioneQuery::create()->filterByCodportale($utente->getCodPortale())
  3861. ->filterByCodmodalita($mpb->getCodmodalita())
  3862. ->filterByCodspedizione($tsb->getCodSpedizione())
  3863. ->filterByCodpackaging($articolo->getCodPackaging())
  3864. ->filterByPesoda($peso, '<=')
  3865. ->filterByPesoa($peso, '>=')
  3866. ->findOne($con);
  3867.  
  3868. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: QUERY SPESE SPEDIZIONE-> codPortale='" . $utente->getCodportale() . "' and codModalita='" . $mpb->getCodmodalita() . "' and codSpedizione='" . $tsb->getCodspedizione() . "' and codPackaging='" . $articolo->getCodpackaging() . "' and pesoDa<=" . $peso . " and pesoA>=" . $peso);
  3869.  
  3870. $totSpese = $mpb->getCosto() + $ssb->getCosto();
  3871.  
  3872. $totSpese = round($totSpese, 2);
  3873.  
  3874. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CONTROLLO SPESE SPEDIZIONE-> TOTALE SPESE " . $totSpese);
  3875.  
  3876. if (intval($params["totaleSpeseSpedizione"]) < ($totSpese - 0.10) || intval($params["totaleSpeseSpedizione"]) > ($totSpese + 0.10)) {
  3877. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_spese_sped")));
  3878. }
  3879. }
  3880. }
  3881. }
  3882. $totale = $totaleCart + $totSpese;
  3883.  
  3884. //TODO EARLTP: il commento serve per ripristinare il funzionamento dopo la pezza
  3885. /*if (round((float)$totaleOrdine, 2) - round((float)$totale, 2) - round((float)$prezzoTransfertToCheck, 2) < 0.01) {
  3886. // PEZZA 2016-02-02: da sistemare!!!
  3887. // i totali differiscono dell'importo del transfert => quindi faccio andare avanti l'ordine
  3888. }else {*/
  3889.  
  3890. //controllo totale con range di 0.10€, se fuori aggiunge errore
  3891. if ($totale < ($totaleOrdine - 0.10) || $totale > ($totaleOrdine + 0.10)) {
  3892. $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_tot_ordine")));
  3893. }
  3894. //}
  3895.  
  3896. $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CONTROLLO IMPORTO ORDINE-> TOTALE ORDINE " . $totaleOrdine);
  3897. $this->logger->log(__FILE__, __LINE__, "L'ordine ricevuto e' di " . intval($params["totaleOrdine"]));
  3898. }
  3899. }
  3900.  
  3901. //-----------------------------------------------------------
  3902.  
  3903. $resultMap["mappa errori"] = $errorsMap;
  3904. return $resultMap;
  3905.  
  3906. } catch (Exception $e) {
  3907. echo $e->getTraceAsString();
  3908. return null;
  3909. }
  3910. }
  3911.  
  3912. //------------------------------------------------------------------------------------------------------------------
  3913. //getListiniServizi: query al db e costruzione albero listini da restituire alla vista
  3914. //------------------------------------------------------------------------------------------------------------------
  3915. /*
  3916. * @param string $codPortale
  3917. * @param string $codLaboratorio
  3918. * @param string $codServizio
  3919. * @param string $codFotografo
  3920. * @param string $tipoUtente
  3921. * @param string $username
  3922. * @param string $password
  3923. * @return string
  3924. */
  3925. public function getListiniServizi($codPortale, $codLaboratorio, $codServizio, $codFotografo, $tipoUtente, $username, $password)
  3926. {
  3927. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  3928.  
  3929. $utente = null;
  3930. $portale = null;
  3931. $fotografo = null;
  3932. $listinoFotografo = null;
  3933. $listinoLaboratorio = null;
  3934. $listinoPortale = null;
  3935.  
  3936. if (!empty($username) && !empty($password)) {
  3937. $utente = UtentiQuery::create()->filterByCodportale($codPortale)
  3938. ->filterByUsername($username)
  3939. ->findOne($con);
  3940.  
  3941. if ($utente == null) {
  3942. $utente = UtentiQuery::create()->filterByCodportaleold($codPortale)
  3943. ->filterByUsername($username)
  3944. ->findOne($con);
  3945. }
  3946. }
  3947.  
  3948. //-----------------------------------
  3949.  
  3950. //PARAMETRI USERNAME E PASSWORD NON PASSATI
  3951. if ($utente == null) {
  3952. $conversione = ConversioneportaliQuery::create()->filterByCodportaleold($codPortale)
  3953. ->filterByCodlaboratorioold(0)
  3954. ->filterByCodfotografoold(0)
  3955. ->filterByCodgruppoold('')
  3956. ->findOne($con);
  3957. if ($conversione != null) {
  3958. $codPortale = $conversione->getCodportalenew();
  3959. }
  3960.  
  3961. $portale = PortaliQuery::create()->filterByCodportale($codPortale)->findOne($con);
  3962.  
  3963. if ($codLaboratorio != null && $codFotografo != null) {
  3964. $fotografo = FotografiQuery::create()->filterByCodportale($codPortale)
  3965. ->filterByCodlaboratorio($codLaboratorio)
  3966. ->filterByCodfotografo($codFotografo)
  3967. ->findOne($con);
  3968. }
  3969. } else {
  3970. $portale = PortaliQuery::create()->filterByCodportale($utente->getCodportale())->findOne($con);
  3971. $fotografo = FotografiQuery::create()->filterByCodportale($utente->getCodportale())
  3972. ->filterByCodlaboratorio($utente->getCodlaboratorio())
  3973. ->filterByCodfotografo($utente->getCodFotografo())
  3974. ->findOne($con);
  3975. }
  3976.  
  3977.  
  3978. if (!empty($portale) && !empty($codLaboratorio) && !empty($codServizio) && !empty($fotografo)) {
  3979. //MAPPA ALBERO SERVIZIO ==> SOLO ARTICOLI E SOTTOARTICOLI PRESENTI PER LABORATORIO
  3980. $albero = new Albero();
  3981. $codPortale = $portale->getCodportale();
  3982. $alberoMap = $albero->getAlberoServizio($codPortale, $codLaboratorio, $codServizio, $tipoUtente, 1);
  3983.  
  3984. $listiniF = ListiniQuery::create()->filterByCodportale($codPortale)
  3985. ->filterByCodlaboratorio($codLaboratorio)
  3986. ->filterByCodlistino($fotografo->getCodpersonalizzato())
  3987. ->filterByCodpersonalizzato('0')
  3988. ->find($con);
  3989. foreach ($listiniF as $listinoF) {
  3990. $listiniFotografo[$listinoF->getCodarticolo()] = $listinoF;
  3991. }
  3992.  
  3993. //MAPPA LISTINI LABORATORIO E PORTALE
  3994. $listiniL = ListiniQuery::create()->filterByCodportale($codPortale)
  3995. ->filterByCodlaboratorio($codLaboratorio)
  3996. ->filterByCodlistino('0')
  3997. ->filterByCodpersonalizzato('0')
  3998. ->find($con);
  3999. foreach ($listiniL as $listinoL) {
  4000. $listiniLaboratorio[$listinoL->getCodarticolo()] = $listinoL;
  4001. }
  4002.  
  4003. $listiniP = ListiniQuery::create()->filterByCodportale($codPortale)
  4004. ->filterByCodlaboratorio('0')
  4005. ->filterByCodlistino('0')
  4006. ->filterByCodpersonalizzato('0')
  4007. ->find($con);
  4008. foreach ($listiniP as $listinoP) {
  4009. $listiniPortale[$listinoP->getCodarticolo()] = $listinoP;
  4010. }
  4011.  
  4012.  
  4013. //MAPPA ARTICOLI LABORATORIO
  4014. $articoli = ArticoliQuery::create()->filterByCodportale($codPortale)
  4015. ->filterByCodlaboratorio($codLaboratorio)
  4016. ->find($con);
  4017. foreach ($articoli as $articolo) {
  4018. $articoliMap[$articolo->getCodarticolo()] = $articolo;
  4019. }
  4020.  
  4021. /** CAMPAGNE - MARZO 2012 **/
  4022. $campagne = CampagneQuery::create()->filterByCodiceportale($codPortale)
  4023. ->filterByDatainizio(date("Y-m-d H:i:s"), "<=")
  4024. ->filterByDatafine(date("Y-m-d H:i:s"), ">=")
  4025. ->find($con);
  4026. $listiniCampagneMap = null;
  4027. if (sizeof($campagne) > 0) {
  4028. foreach ($campagne as $campagna) {
  4029. $escluso = $codFotografo != null ? EsclusionefotograficampagneQuery::create()->filterByCodportale($codPortale)
  4030. ->filterByCodlaboratorio($codLaboratorio)
  4031. ->filterByCodfotografo($codFotografo)
  4032. ->where("(codCampagna='" . $campagna->getCodiceCampagna() . "' OR codCampagna='')")
  4033. ->findOne($con)
  4034. : null;
  4035. if ($escluso == null) {
  4036. $listiniCampagna = $campagna->getListinoPromozionale();
  4037.  
  4038. foreach ($listiniCampagna as $listinoCampagna) {
  4039. $listiniCampagneMap[$listinoCampagna->getCodicearticolo()] = $listinoCampagna;
  4040. }
  4041. }
  4042. }
  4043. }
  4044.  
  4045. $listino = null;
  4046. $artToTree = null;
  4047.  
  4048. $legatoFotografo = ($fotografo == null) ? 0 : 1;
  4049.  
  4050. foreach (array_keys($alberoMap) as $node) {
  4051. $ab = $alberoMap[$node];
  4052.  
  4053. //PER GLI ARTICOLI SETTO IL LISTINO E LE EVENTUALI PAGINE AGGIUNTIVE
  4054. if ($ab != null && strlen($ab->getCodalbero()) == 8) {
  4055. $art = $articoliMap[$ab->getCodarticolo()];
  4056.  
  4057. if ($art != null) {
  4058. $art->setArticolotransfert($fotografo, $legatoFotografo);
  4059.  
  4060. if ($listiniFotografo != null) {
  4061. $listino = $listiniFotografo[$ab->getCodarticolo()];
  4062. }
  4063. if ($listino == null) {
  4064. $listino = $listiniLaboratorio[$ab->getCodarticolo()];
  4065. }
  4066. if ($listino == null) {
  4067. $listino = $listiniPortale[$ab->getCodarticolo()];
  4068. }
  4069.  
  4070. if ($listino != null) {
  4071. $art->setListino($listino);
  4072. $artToTree[$art->getCodArticolo()] = $art;
  4073. }
  4074.  
  4075. if (sizeof($listiniCampagneMap) && $listiniCampagneMap[$art->getCodArticolo()] != null) {
  4076. $listinoPromo = $listiniCampagneMap[$art->getCodArticolo()];
  4077. $art->setListinoPromozionale($listinoPromo);
  4078. }
  4079.  
  4080. //PAGINE AGGIUNTIVE
  4081. $listino = null;
  4082.  
  4083. if ($art->getArticoloCorrelato2() != null) {
  4084. $pa = $articoliMap[$art->getArticoloCorrelato2()];
  4085.  
  4086. if ($pa != null) {
  4087. if ($listiniFotografo != null) {
  4088. $listino = $listiniFotografo[$pa->getCodArticolo()];
  4089. }
  4090. if ($listino == null) {
  4091. $listino = $listiniLaboratorio[$pa->getCodArticolo()];
  4092. }
  4093. if ($listino == null) {
  4094. $listino = $listiniPortale[$pa->getCodArticolo()];
  4095. }
  4096. if ($listino != null) {
  4097. $pa->setListino($listino);
  4098. $artToTree[$pa->getCodArticolo()] = $pa;
  4099. }
  4100.  
  4101. if (sizeof($listiniCampagneMap) > 0 && $listiniCampagneMap[$pa->getCodArticolo()] != null) {
  4102. $listinoPromo = $listiniCampagneMap[$pa->getCodArticolo()];
  4103. $pa->setListinoPromozionale($listinoPromo);
  4104. }
  4105. }
  4106. $listino = null;
  4107. }
  4108. }
  4109. }
  4110. }
  4111. }
  4112. $html = $this->getHtmlFamiglie($alberoMap, $artToTree);
  4113. return (string)$html;
  4114. }
  4115.  
  4116. //------------------------------------------------------------------------------------------------------------------
  4117. //getHtmlFamiglie: genera tabella html per listini
  4118. //------------------------------------------------------------------------------------------------------------------
  4119. /**
  4120. * @return string
  4121. */
  4122. private function getHtmlFamiglie($alberi, $articoli)
  4123. {
  4124. $html = "<table class='pricing_list'>";
  4125. ksort($alberi);
  4126.  
  4127. foreach ($alberi as $albero) {
  4128. $nodeCode = $albero->getCodalbero();
  4129.  
  4130. if (strlen($nodeCode) == 4 && strpos($albero->getTitolo(), "***CANCELLED***") === false) {
  4131. $html .= "<tr>";
  4132. $html .= " <th class='famiglie' colspan=2>" . $albero->getTitolo() . "</th>";
  4133. $html .= "</tr>";
  4134. $html .= $this->getHtmlFigli($nodeCode, $alberi, $articoli);
  4135. //$html .= "<tr><td style='border: none;' height=20></td></tr>";
  4136. }
  4137. }
  4138.  
  4139. $html .= "</table>";
  4140.  
  4141. return $html;
  4142. }
  4143.  
  4144. //------------------------------------------------------------------------------------------------------------------
  4145. /**
  4146. * @return string
  4147. */
  4148. private function getHtmlFigli($node, $alberi, $articoli)
  4149. {
  4150. $html = "";
  4151. ksort($alberi);
  4152.  
  4153. foreach ($alberi as $albero) {
  4154. $nodeCode = $albero->getCodalbero();
  4155.  
  4156. //NODO SOTTOFAMIGLIA
  4157. if (strlen($node) == 4 && strlen($nodeCode) == 6 && substr($nodeCode, 0, 4) == $node) {
  4158. if (substr($nodeCode, 4, 6) == "00" && $albero == null) {
  4159. $html .= $this->getHtmlFigli($nodeCode, $alberi, $articoli);
  4160. } else {
  4161. $html .= "<tr>";
  4162. $html .= " <th colspan=2 class='sottofamiglie'>" . $albero->getTitolo() . "</th>";
  4163. $html .= "</tr>";
  4164. $html .= $this->getHtmlFigli($nodeCode, $alberi, $articoli);
  4165. }
  4166. }
  4167.  
  4168. if (strlen($node) == 6 && strlen($nodeCode) == 8 && substr($nodeCode, 0, 6) == $node) {
  4169. $articolo = $articoli[$albero->getCodarticolo()];
  4170.  
  4171. if ($articolo != null) {
  4172. //stampa listino articolo
  4173. $html .= "<tr>";
  4174. $html .= " <td class ='articoli'>" . $albero->getTitolo() . "</td>";
  4175. $html .= " <td class ='tab_prezzi'>";
  4176.  
  4177. if ($articolo->getListino() != null) {
  4178. $html .= $this->getTableListini($articolo, $articoli);
  4179. }
  4180.  
  4181. $html .= " </td>";
  4182. $html .= "</tr>";
  4183.  
  4184. $html .= $this->getHtmlFigli($nodeCode, $alberi, $articoli);
  4185.  
  4186. if ($articolo->getArticoloTransfert() != null) {
  4187. $html .= "<tr>";
  4188. $html .= "<td class='articoli'>" . $articolo->getArticoloTransfert()->getDesArticolo() . "</td>";
  4189. $html .= "<td class='listini_right' prezzo_agg'>" . $articolo->getArticoloTransfert()->getListino()->getPrezzo1() . "&nbsp;&euro;</td>";
  4190. $html .= "</tr>";
  4191. }
  4192.  
  4193. if ($articolo->getArticoloCorrelato2() != null) {
  4194. $pa = $articoli[$articolo->getArticoloCorrelato2()];
  4195.  
  4196. if ($pa != null) {
  4197. //stampa listino articolo
  4198. $html .= "<tr>";
  4199. $html .= " <td class='articoli' style='padding-left:40px;'>" . $pa->getDesArticolo() . "</td>";
  4200. $html .= " <td class='listini_right prezzo_agg'>";
  4201. $html .= $this->getTableListini($pa, $articoli);
  4202. $html .= " </td></tr>";
  4203. }
  4204. }
  4205. }
  4206. }
  4207.  
  4208. //NODO SOTTOARTICOLO
  4209. if (strlen($node) == 8 && strlen($nodeCode) == 10 && ubstr($nodeCode, 0, 6) == $node) {
  4210. $articolo = $articoli[$albero->getCodArticolo()];
  4211. if ($articolo != null) {
  4212. $html .= "<tr>";
  4213. $html .= "<td class='articoli' style='padding-left:60px;'>" . $albero->getTitolo() . "</td>";
  4214. $html .= "<td class='listini_right prezzo_agg'>&nbsp;</td></tr>";
  4215. }
  4216. }
  4217. }
  4218. return $html;
  4219. }
  4220.  
  4221. private function getTableListini($articolo, $articoli)
  4222. {
  4223.  
  4224. $listiniMap = null;
  4225. $html = "<table width=100% cellpadding=0 cellspacing=0>";
  4226.  
  4227. if ($articolo->getListino() != null) {
  4228. $str = "";
  4229. $prezzo = "";
  4230.  
  4231. $listiniMap["quantita1"] = (int)$articolo->getListino()->getQuantita1();
  4232. $listiniMap["quantita2"] = (int)$articolo->getListino()->getQuantita2();
  4233. $listiniMap["quantita3"] = (int)$articolo->getListino()->getQuantita3();
  4234. $listiniMap["quantita4"] = (int)$articolo->getListino()->getQuantita4();
  4235. $listiniMap["quantita5"] = (int)$articolo->getListino()->getQuantita5();
  4236.  
  4237. $listiniMap["prezzo1"] = "" . $articolo->getListino()->getPrezzo1();
  4238. $listiniMap["prezzo2"] = "" . $articolo->getListino()->getPrezzo2();
  4239. $listiniMap["prezzo3"] = "" . $articolo->getListino()->getPrezzo3();
  4240. $listiniMap["prezzo4"] = "" . $articolo->getListino()->getPrezzo4();
  4241. $listiniMap["prezzo5"] = "" . $articolo->getListino()->getPrezzo5();
  4242.  
  4243. if ($articolo->getListinoPromozionale() != null) {
  4244.  
  4245. $listiniMap["quantita1"] = (int)$articolo->getListinoPromozionale()->getQuantita1();
  4246. $listiniMap["quantita2"] = (int)$articolo->getListinoPromozionale()->getQuantita2();
  4247. $listiniMap["quantita3"] = (int)$articolo->getListinoPromozionale()->getQuantita3();
  4248. $listiniMap["quantita4"] = (int)$articolo->getListinoPromozionale()->getQuantita4();
  4249. $listiniMap["quantita5"] = (int)$articolo->getListinoPromozionale()->getQuantita5();
  4250.  
  4251. $listiniMap["prezzo1"] = "" . $articolo->getListinoPromozionale()->getPrezzo1();
  4252. $listiniMap["prezzo2"] = "" . $articolo->getListinoPromozionale()->getPrezzo2();
  4253. $listiniMap["prezzo3"] = "" . $articolo->getListinoPromozionale()->getPrezzo3();
  4254. $listiniMap["prezzo4"] = "" . $articolo->getListinoPromozionale()->getPrezzo4();
  4255. $listiniMap["prezzo5"] = "" . $articolo->getListinoPromozionale()->getPrezzo5();
  4256.  
  4257. }
  4258.  
  4259. for ($i = 1; $i < 6; $i++) {
  4260. //PRIMA RIGA
  4261. if ($i == 1) {
  4262. if ((int)$listiniMap["quantita" . $i] > 0) {
  4263. $str = "da 1 a " . ((int)$listiniMap["quantita" . $i] - 1);
  4264. $prezzo = (string)number_format((float)$listiniMap["prezzo" . $i], 2, ',', '');
  4265.  
  4266. $html .= "<tr>";
  4267. $html .= " <td class='listini_left'>" . $str . "</td>";
  4268. $html .= " <td class='listini_right'>" . $prezzo . "&nbsp;&euro;</td>";
  4269. $html .= "</tr>";
  4270. } else {
  4271. $str = "&nbsp;";
  4272. $prezzo = (string)number_format((float)$listiniMap["prezzo" . $i], 2, ',', '');
  4273.  
  4274. $html .= "<tr>";
  4275. $html .= " <td class='listini_left'>" . $str . "</td>";
  4276. $html .= " <td class='listini_right'>" . $prezzo . "&nbsp;&euro;</td>";
  4277. $html .= "</tr>";
  4278. break;
  4279. }
  4280. }
  4281.  
  4282. //ULTIMA RIGA
  4283. if ($i == 5 || (int)$listiniMap["quantita" . ($i + 1)] == 0) {
  4284. $str = "oltre " . (int)$listiniMap["quantita" . $i];
  4285. $prezzo = (string)number_format((float)$listiniMap["prezzo" . ($i + 1)], 2, ',', '');
  4286.  
  4287. $html .= "<tr>";
  4288. $html .= " <td class='listini_left'>" . $str . "</td>";
  4289. $html .= " <td class='listini_right'>" . $prezzo . "&nbsp;&euro;</td>";
  4290. $html .= "</tr>";
  4291. break;
  4292. } //SCAGLIONI
  4293. else {
  4294. $str = "da " . (int)$listiniMap["quantita" . $i] . " a " . (((int)$listiniMap["quantita" . ($i + 1)]) - 1);
  4295. $prezzo = (string)number_format((float)$listiniMap["prezzo" . ($i + 1)], 2, ',', '');
  4296.  
  4297. $html .= "<tr>";
  4298. $html .= " <td class='listini_left'>" . $str . "</td>";
  4299. $html .= " <td class='listini_right'>" . $prezzo . "&nbsp;&euro;</td>";
  4300. $html .= "</tr>";
  4301. }
  4302. }
  4303. }
  4304. $html .= "</table>";
  4305. return $html;
  4306. }
  4307. //------------------------------------------------------------------------------------------------------------------
  4308. /* Funzione che a partire da una transazione fa il login dell'utente
  4309. * Serve per vedere i "miei ordini" dal fototaxi vecchio: dopo aver premuto il pulsante c'è un passaggio obbligato
  4310. * nella orderservlet nella quale si fa un finto login, in realtà viene creata una transazione il cui id viene passato
  4311. * come parametro, richiamando questa funzione si fa il login vero e proprio
  4312. *
  4313. * @param string $idTransazione
  4314. * return array
  4315. */
  4316. public function getUserByTransaction($idTransazione, $host)
  4317. {
  4318. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  4319. $idUtente = TransazioniapplicazioniQuery::create()->filterById($idTransazione)->select("Fkutente")->findOne($con);
  4320. $accountService = new Account_Service();
  4321. $utente = $accountService->loginByUserId($idUtente, $host);
  4322. return $utente;
  4323. }
  4324.  
  4325. //------------------------------------------------------------------------------------------------------------------
  4326. /**
  4327. * @param string $sessionId
  4328. * @param array $utente
  4329. * @throws PropelException
  4330. * @throws ServiceException
  4331. */
  4332. public function createTransaction($sessionId, $utente)
  4333. {
  4334. try {
  4335. $internalTransaction = true;
  4336. $con = Propel::getConnection(DATASOURCE_NAME);
  4337. $con->beginTransaction();
  4338. $config = Zend_Registry::get('Redarea_Configuration');
  4339. $id_prefix = $config->db->id->prefix;
  4340. $transactionId = $id_prefix . uniqid();
  4341. //setto a stinga vuota eventuali parametri facoltativi mancanti
  4342. $utente["Codportale"] = !empty($utente["Codportale"]) ? $utente["Codportale"] : "";
  4343. $utente["Codlaboratorio"] = !empty($utente["Codlaboratorio"]) ? $utente["Codlaboratorio"] : "";
  4344. $utente["Codfotografo"] = !empty($utente["Codfotografo"]) ? $utente["Codfotografo"] : "";
  4345. $utente["Idutente"] = !empty($utente["Idutente"]) ? $utente["Idutente"] : "";
  4346.  
  4347. $transazione = new Transazioniapplicazioni();
  4348. $transazione->setId($transactionId);
  4349. $transazione->setCodportale($utente["Codportale"]);
  4350. $transazione->setCodlaboratorio($utente["Codlaboratorio"]);
  4351. $transazione->setCodfotografo($utente["Codfotografo"]);
  4352. //$transazione->setCodgruppo();
  4353. //$transazione->setCodagente($utente->getCodagente());
  4354. $transazione->setUsername($utente["Username"]);
  4355. $transazione->setFkutente($utente["Idutente"]);
  4356. $transazione->setDatainserimento(date("Y-m-d H:i:s"));
  4357. $transazione->setFkprogetto("");
  4358. $transazione->setClient("FOTOTAXI-OLD");
  4359. $transazione->setSessionid($sessionId);
  4360. $transazione->save($con);
  4361.  
  4362. if ($internalTransaction) {
  4363. $con->commit();
  4364. }
  4365. } catch (Exception $e) {
  4366. if ($internalTransaction) {
  4367. $con->rollBack();
  4368. }
  4369. $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
  4370. $this->logger->log(__FILE__, __LINE__, $e->getTraceAsString(), Zend_Log::ERR);
  4371. throw new ServiceException($e->getMessage());
  4372. }
  4373. }
  4374.  
  4375. /**
  4376. * @param array $cartItems
  4377. * @param Promozioni $promozione
  4378. * @param Credits $credits
  4379. * @param bool $applicaPromoPagAgg
  4380. * @return bool
  4381. */
  4382. private function verificaApplicabilitaCondizioni($cartItems, $promozione, $credits, $applicaPromoPagAgg)
  4383. {
  4384. //TODO EARLTP: verificare esistenza funzioni
  4385. $condClassi = $promozione->getCondclassearticoli(); //java: getCondListClassi();
  4386. $condArticoli = $promozione->getCondlistaarticoli(); //java : getCondListaArticoliToList();
  4387.  
  4388. $qtaTotale = 0;
  4389. $importoTotale = 0;
  4390.  
  4391. foreach ($cartItems as $item) {
  4392.  
  4393. if (
  4394. (count($condClassi) == 1 && $condClassi[0] == "" && count($condArticoli) == 0) ||
  4395. ($this->verificaAppartenenzaClassiArticoli($condClassi, $item->getArticolo()->getClasse()) || $this->verificaAppartenenzaClassiArticoli($condArticoli, $item->getArticolo()->getCodArticolo()))
  4396. ) {
  4397.  
  4398. $qtaTotale += $item->getQuantita();
  4399. $importoTotale += $item->getQuantita() * $item->getPrezzo();
  4400.  
  4401. }
  4402. }
  4403.  
  4404. /* nel caso di promozioni:
  4405. - di tipo qta omaggio, 3x2, a prezzo fisso, kit
  4406. - con condizione importo minimo ordine
  4407. - condizione valida su tutte le classi articolo
  4408. l'importo dell'ordine deve essere al netto dello sconto
  4409. */
  4410. $allClasses = (count($condClassi) == 1 && $condClassi[0] == "" && count($condArticoli) == 0);
  4411. if (
  4412. ($promozione->getFlagtipopromozione() == 0 || $promozione->getFlagtipopromozione() == 4 || $promozione->getFlagtipopromozione() == 6) &&
  4413. $allClasses &&
  4414. $promozione->getImpminimoordine() > 0
  4415. ) {
  4416. $sconto = 0;
  4417. if ($promozione->getFlagtipopromozione() == 0) {
  4418.  
  4419. if ($promozione->getPercsconto() == 0) {
  4420. $result = $this->calcolaScontoQtaOmaggio($cartItems, $promozione, $credits, $applicaPromoPagAgg, 0);
  4421. $sconto = (Double)$result["totaleSconto"];
  4422. } else {
  4423. $sconto = $this->calcolaSconto3x2($cartItems, $promozione, $applicaPromoPagAgg);
  4424. }
  4425. } elseif ($promozione->getFlagtipopromozione() == 4) {
  4426. $sconto = $this->calcolaScontoPrezzoFisso($cartItems, $promozione, $applicaPromoPagAgg);
  4427. } elseif ($promozione->getFlagTipoPromozione() == 6) {
  4428. $sconto = $this->calcolaScontoKit($cartItems, $promozione, $credits, $applicaPromoPagAgg, 0);
  4429. }
  4430.  
  4431. $sconto = (float)($sconto + 0.005);
  4432. $importoTotale -= $sconto;
  4433. }
  4434.  
  4435. if ($qtaTotale >= $promozione->getQtaminimaordine() && $importoTotale >= $promozione->getImpminimoordine()) {
  4436. return true;
  4437. }
  4438.  
  4439. return false;
  4440. }
  4441.  
  4442. //------------------------------------------------------------------------------------------------------------------
  4443. //funzioni di test
  4444. //------------------------------------------------------------------------------------------------------------------
  4445. /**
  4446. * @return array
  4447. */
  4448. public function testGetListino()
  4449. {
  4450. $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
  4451.  
  4452. $utente = UtentiQuery::create()->filterByCodportale('rikorda')
  4453. ->filterByUsername('giorgia.gardini@libero.it')
  4454. ->findOne($con);
  4455.  
  4456. $articolo = ArticoliQuery::create()->filterByCodportale($utente->getCodportale())
  4457. ->filterByCodlaboratorio($utente->getCodLaboratorio())
  4458. ->filterByCodarticolo("10x13-lucida")
  4459. ->findOne($con);
  4460.  
  4461. $fotografo = FotografiQuery::create()->filterByCodportale($utente->getCodportale())
  4462. ->filterByCodlaboratorio($utente->getCodLaboratorio())
  4463. ->filterByCodfotografo($utente->getCodFotografo())
  4464. ->findOne($con);
  4465.  
  4466. $listino = $this->getListino($articolo, $utente, $fotografo);
  4467.  
  4468. return $listino;
  4469. }
  4470. }
Add Comment
Please, Sign In to add comment