Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by IntelliJ IDEA.
- * User: Lux
- * Date: 16/07/12
- * Time: 16.04
- * To change this template use File | Settings | File Templates.
- */
- require_once 'Common/BaseService.php';
- require_once 'Account/Service.php';
- require_once 'Fototaxi/ExternalService.php';
- require_once 'Fototaxi/UtilsService.php';
- require_once 'dto/fototaxi/GetAllArticoliResponse.php';
- require_once 'dto/fototaxi/GetCliserResponse.php';
- require_once 'dto/fototaxi/GetCliser2Response.php';
- require_once 'dto/fototaxi/GetUtenteFotografoResponse.php';
- require_once 'dto/fototaxi/GetUtenteResponse.php';
- require_once 'dto/fototaxi/GetTemaResponse.php';
- require_once 'dto/fototaxi/GetCliserPacchettoResponse.php';
- require_once 'Batch/PagamentiUnicredit.php';
- require_once APPLICATION_PATH . '/models/dto/account/UserItem.php';
- class Fototaxi_OldService extends Common_BaseService
- {
- // Home ftp - serve a getXmlServizi
- const FTP_HOME = '/var/labo/home';
- const LOGIN_STATUS_OK = 0;
- // Mappatura costanti tornate dai servizi esterni - uguali alla classe ExternalService
- const LOGIN_STATUS_USER_NOT_FOUND = 30;
- const LOGIN_STATUS_USER_NOT_ACTIVE = 31;
- const LOGIN_STATUS_USER_WRONG_PASS = 32;
- const LOGIN_STATUS_USER_WRONG_USER = 33;
- const EXTERNAL_LOGIN_DISABLED_VIRTUAL_SHOP = 40;
- /**
- * Per i test - configurazione cartella ftp-home con un percorso accessibile al filesystem della macchina che
- * lancia i test
- * @var string
- */
- public $alternativeFtpHome;
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * @param struct|array $params
- * @return struct|array
- */ //@return GetAllArticoliResponse
- public function getAllArticoli($params)
- {
- $time_start = microtime(true); /*START TIME LOG*/
- $output = new GetAllArticoliResponse();
- $codPortale = array_key_exists('codPortale', $params) ? (string)$params['codPortale'] : null;
- $username = array_key_exists('username', $params) ? (string)$params['username'] : null;
- $password = array_key_exists('password', $params) ? (string)$params['password'] : null;
- // Login
- $loginStatus = $this->login($codPortale, $username, $password, false);
- if ($loginStatus != self::LOGIN_STATUS_OK) {
- $output->setStatusMessage(GetAllArticoliResponse::STATUS_USER_NOT_FOUND, array($codPortale, $username, $password));
- $strout = $output->__toString();
- $md5 = md5(Zend_Json::encode($strout));
- $strout = base64_encode(gzcompress(Zend_Json::encode($strout)));
- return array('md5' => $md5, 'data' => $strout);
- }
- try {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $utente = UtentiQuery::create()->filterByCodportale($codPortale)->filterByUsername($username)->findOne($con);
- //------
- // GESTIONE CONVERSIONI
- if (empty($utente)) {
- $utente = UtentiQuery::create()->filterByCodportaleold($codPortale)->filterByUsername($username)->findOne($con);
- }
- $codPortale = empty($utente) ? $codPortale : $utente->getCodportale();
- //------------------------------------------
- $portale = PortaliQuery::create()->filterByCodportale($codPortale)->findOne($con);
- if (empty($portale)) {
- throw new Exception("Portale inesistente: $codPortale");
- }
- if (($portale->getTipoportale() == 'D') || ($utente->getCodfotografo() == 0)) {
- $fotografo = FotografiQuery::create()->filterByCodportale($utente->getcodPortale())->filterByAbilitato(1)->findOne($con);
- } else {
- $fotografo = FotografiQuery::create()
- ->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getCodlaboratorio())
- ->filterByCodfotografo($utente->getCodfotografo())
- ->findOne($con);
- }
- if (empty($fotografo)) {
- throw new Exception("Fotografo non esistente per portale: " . $portale->getCodportale() . " laboratorio: "
- . $utente->getCodlaboratorio() . " fotografo: " . $utente->getCodfotografo());
- }
- $codLaboratorio = (string)$utente->getCodlaboratorio();
- // RECUPERO DEI SERVIZI, SOLTANTO QUELLI ASSOCIATI AL LABORATORIO
- $servizi = ServiziQuery::create()
- ->filterByCodportale($portale->getCodportale())
- ->addJoinObject(new Join(array(ServiziPeer::CODPORTALE, ServiziPeer::CODSERVIZIO),
- array(ServizilaboratoriPeer::CODPORTALE, ServizilaboratoriPeer::CODSERVIZIO),
- Criteria::LEFT_JOIN))
- ->where(ServizilaboratoriPeer::CODLABORATORIO . " = '$codLaboratorio'")
- ->select(array('Fktiposervizio'))
- ->distinct()
- ->find($con)
- ->toArray();
- // SE NON CI SONO SERVIZI ASSOCIATI AL LABORATORIO SI CONSIDERA 'STAMPA FOTO' QUELLO DI DEFAULT
- if (count($servizi) == 0) {
- $servizi = array('SS');
- }
- $queryArticoli = ArticoliQuery::create()
- ->filterByCodportale($portale->getCodportale())
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByVisualizzabile(array(1, 2, 3))
- ->filterByFlagtipoutente(array($utente->getTipo(), 'B'))
- ->filterByFktiposervizio($servizi);
- $modalita = array_key_exists('modalita', $params) ? $params['modalita'] : null;
- if (!($modalita === null) && (((int)$modalita) !== 0)) {
- // Modalità impostata
- $mod = (int)$modalita;
- $queryArticoli = $queryArticoli->filterByFlagmodalita(array(0, $mod));
- }
- $this->logger->log(__FILE__, __LINE__, "QUERY GET ALL ARTICOLI: " . $queryArticoli->toString());
- $articoliList = $queryArticoli->find($con);
- if (count($articoliList) < 1) {
- throw new Exception("Articoli non Presenti per portale: $codPortale username: $username password: $password");
- }
- // Listini
- $listiniFotografo = ListiniQuery::create()
- ->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getCodlaboratorio())
- ->filterByCodlistino($fotografo->getCodpersonalizzato())
- ->filterByCodpersonalizzato('0')
- ->find($con);
- $listiniLaboratorio = ListiniQuery::create()
- ->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getCodlaboratorio())
- ->filterByCodlistino('0')
- ->filterByCodpersonalizzato('0')
- ->find($con);
- $listiniPortale = ListiniQuery::create()
- ->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio('0')
- ->filterByCodlistino('0')
- ->filterByCodpersonalizzato('0')
- ->find($con);
- // CAMPAGNE PROMOZIONALI - MAR 2012
- $now = new DateTime();
- $campagne = CampagneQuery::create()
- ->filterByCodiceportale($utente->getCodportale())
- ->filterByDatainizio(array('max' => $now))
- ->filterByDatafine(array('min' => $now))
- ->filterByTipo(array('ALL'), Criteria::IN)
- ->addJoin(array(CampagnePeer::CODICEPORTALE, CampagnePeer::CODICEPROMOZIONE),
- array(PromozioniPeer::CODPORTALE, PromozioniPeer::CODPROMOZIONE), Criteria::LEFT_JOIN)
- ->where(PromozioniPeer::TIPOUTENTE . " IN ('B', '" . $utente->getTipo() . "')")
- ->find($con);
- $listiniCampagneMap = array();
- foreach ($campagne as $campagna) {
- //$campagna = new Campagne();
- $escluso = EsclusionefotograficampagneQuery::create()
- ->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getCodlaboratorio())
- ->filterByCodfotografo($utente->getCodfotografo())
- ->filterByCodcampagna(array($campagna->getCodicecampagna(), ''))
- ->findOne($con);
- $promoCampagna = $campagna->getPromozione();
- if (empty($escluso) &&
- !empty($promoCampagna) &&
- $promoCampagna->isApplicabileUtente($utente) &&
- $promoCampagna->getCheckTemi() == 0 &&
- $promoCampagna->isApplicabileClient('FOTOTAXIOLD') &&
- $promoCampagna->isApplicabileFotografo($utente)
- ) {
- // Fotografo non escluso, recupero listino promozionale
- $listiniCampagna = ListinipromozionaliQuery::create()
- ->filterByCodiceportale($campagna->getCodiceportale())
- ->filterByCodicepromozione($campagna->getCodicepromozione())
- ->find($con);
- foreach ($listiniCampagna as $listinoCampagna) {
- $listinoCampagnaMap = array();
- $listinoCampagnaMap['codPortale'] = $listinoCampagna->getCodiceportale();
- $listinoCampagnaMap['codPromozione'] = (string)$listinoCampagna->getCodicepromozione();
- $listinoCampagnaMap['codArticolo'] = $listinoCampagna->getCodicearticolo();
- $listinoCampagnaMap['prezzo1'] = ''. (float)$listinoCampagna->getPrezzo1();
- $listinoCampagnaMap['quantita1'] = ''. (int)$listinoCampagna->getQuantita1();
- $listinoCampagnaMap['prezzo2'] = ''. (float)$listinoCampagna->getPrezzo2();
- $listinoCampagnaMap['quantita2'] = ''. (int)$listinoCampagna->getQuantita2();
- $listinoCampagnaMap['prezzo3'] = ''. (float)$listinoCampagna->getPrezzo3();
- $listinoCampagnaMap['quantita3'] = ''. (int)$listinoCampagna->getQuantita3();
- $listinoCampagnaMap['prezzo4'] = ''. (float)$listinoCampagna->getPrezzo4();
- $listinoCampagnaMap['quantita4'] = ''. (int)$listinoCampagna->getQuantita4();
- $listinoCampagnaMap['prezzo5'] = ''. (float)$listinoCampagna->getPrezzo5();
- $listinoCampagnaMap['quantita5'] = ''. (int)$listinoCampagna->getQuantita5();
- $listinoCampagnaMap['dataIns'] = (string)$listinoCampagna->getDatains();
- // Conversione ad una mappa listino promozionale adatta all'output servizi
- $listiniCampagneMap[$listinoCampagna->getCodicearticolo()] = $listinoCampagnaMap;
- }
- }
- }
- // FINE CAMPAGNE PROMOZIONALI
- $credits = $this->_getCredits($con, $portale, $utente);
- foreach ($credits as $credit) {
- $credit = $this->__toPromo($credit);
- if ($credit->getFlagtipopromozione() == 4) {
- $listiniPrezzoFisso = ListinipromozionaliQuery::create()
- ->filterByCodiceportale($credit->getCodportale())
- ->filterByCodicepromozione($credit->getCodpromozione())
- ->find($con);
- foreach ($listiniPrezzoFisso as $listinoPrezzoFisso) {
- $listinoPrezzoFissoMap = array();
- $listinoPrezzoFissoMap['codPortale'] = $listinoPrezzoFisso->getCodiceportale();
- $listinoPrezzoFissoMap['codPromozione'] = (string)$listinoPrezzoFisso->getCodicepromozione();
- $listinoPrezzoFissoMap['codArticolo'] = $listinoPrezzoFisso->getCodicearticolo();
- $listinoPrezzoFissoMap['prezzo1'] = ''. (float)$listinoPrezzoFisso->getPrezzo1();
- $listinoPrezzoFissoMap['quantita1'] = ''. (int)$listinoPrezzoFisso->getQuantita1();
- $listinoPrezzoFissoMap['prezzo2'] = ''. (float)$listinoPrezzoFisso->getPrezzo2();
- $listinoPrezzoFissoMap['quantita2'] = ''. (int)$listinoPrezzoFisso->getQuantita2();
- $listinoPrezzoFissoMap['prezzo3'] = ''. (float)$listinoPrezzoFisso->getPrezzo3();
- $listinoPrezzoFissoMap['quantita3'] = ''. (int)$listinoPrezzoFisso->getQuantita3();
- $listinoPrezzoFissoMap['prezzo4'] = ''. (float)$listinoPrezzoFisso->getPrezzo4();
- $listinoPrezzoFissoMap['quantita4'] = ''. (int)$listinoPrezzoFisso->getQuantita4();
- $listinoPrezzoFissoMap['prezzo5'] = ''. (float)$listinoPrezzoFisso->getPrezzo5();
- $listinoPrezzoFissoMap['quantita5'] = ''. (int)$listinoPrezzoFisso->getQuantita5();
- $listinoPrezzoFissoMap['dataIns'] = (string)$listinoPrezzoFisso->getDatains();
- $listiniCampagneMap[$listinoPrezzoFisso->getCodicearticolo()] = $listinoPrezzoFissoMap;
- }
- }
- }
- $articoliServiziMap = array();
- foreach ($articoliList as $articolo) {
- //$articolo = new Articoli();
- $articoloOut = new __Article();
- // Creazione oggetto di output
- $articoloOut->setCodArticolo($articolo->getCodarticolo());
- $articoloOut->setCodPortale($articolo->getCodportale());
- $articoloOut->setCodLaboratorio($articolo->getCodlaboratorio());
- $articoloOut->setCodArticoloLabo('' . (int)$articolo->getCodarticololabo());
- $codLayoutLabo = (string)$articolo->getCodlayoutlabo();
- $articoloOut->setCodLayoutLabo($codLayoutLabo);
- $articoloOut->setDesArticolo($articolo->getDesarticolo());
- $articoloOut->setUrlLogo((string)$articolo->getUrllogo());
- $articoloOut->setVisualizzabile((string)$articolo->getVisualizzabile());
- $articoloOut->setQualityHighSize((string)$articolo->getQualityhighsize());
- $articoloOut->setQualityMediumSize((string)$articolo->getQualitymediumsize());
- $articoloOut->setQualityLowSize((string)$articolo->getQualitylowsize());
- $articoloOut->setArticoloCorrelato1((string)$articolo->getArticolocorrelato1());
- $articoloOut->setArticoloCorrelato2((string)$articolo->getArticolocorrelato2());
- $articoloOut->setArticoloCorrelato3((string)$articolo->getArticolocorrelato3());
- $articoloOut->setPackaging((string)$articolo->getPackaging());
- $articoloOut->setAbilitato((string)$articolo->getAbilitato());
- $articoloOut->setInfoOrdine((string)$articolo->getInfoordine());
- $articoloOut->setRapporto(($articolo->getRapporto() == 0 ? "0.0" : ((string)$articolo->getRapporto())));
- $articoloOut->setCodPackaging((string)$articolo->getCodpackaging());
- $articoloOut->setGrammi((string)$articolo->getGrammi());
- $articoloOut->setIva((string)$articolo->getIva());
- $articoloOut->setQtMinimaOrdine((string)$articolo->getQtminimaordine());
- $articoloOut->setFlagArticoloComposito((string)$articolo->getFlagarticolocomposito());
- $articoloOut->setMaxTesto1((string)$articolo->getMaxtesto1());
- $articoloOut->setMaxTesto2((string)$articolo->getMaxtesto2());
- $articoloOut->setClasse($articolo->getClasse());
- $articoloOut->setAltezza((string)$articolo->getAltezza());
- // Per assemblatore
- $articoloOut->setMinPagine((string)$articolo->getMinpagine());
- $articoloOut->setMaxPagine((string)$articolo->getMaxpagine());
- $articoloOut->setCarta($articolo->getCarta());
- $articoloOut->setFormatoComposizione($articolo->getFormatocomposizione());
- $articoloOut->setModalita((string)$articolo->getFlagmodalita());
- // Per baco assemblatore
- $articoloOut->setTipoServizio($articolo->getFktiposervizio());
- $articoloOut->setOrientamento($articolo->getOrientamento());
- //*********************************
- // IMPOSTAZIONE ARTICOLO TRANSFERT
- //*********************************
- $articoloTransfert = null;
- $listinoTransfert = null;
- $legatoFotografo = $utente->getLegatofotografo();
- // Se non esiste un articolo transfert, la query viene tralasciata
- /* simo: modifica marzo 2015 - transfert differenziato utente finale /fotografo */
- $articoloTransfert = null;
- if ($utente->getTipo() == "F" && strlen(trim($articolo->getArticolocorrelato4())) > 0) {
- $articoloTransfert = ArticoliQuery::create()
- ->filterByCodportale($articolo->getCodportale())
- ->filterByCodlaboratorio($articolo->getCodlaboratorio())
- ->filterByVisualizzabile(0)
- ->filterByCodarticolo($articolo->getArticolocorrelato4())
- ->findOne($con);
- }
- if ($articoloTransfert == null && strlen(trim($articolo->getArticolocorrelato1())) > 0) {
- $articoloTransfert = ArticoliQuery::create()
- ->filterByCodportale($articolo->getCodportale())
- ->filterByCodlaboratorio($articolo->getCodlaboratorio())
- ->filterByVisualizzabile(0)
- ->filterByCodarticolo($articolo->getArticolocorrelato1())
- ->findOne($con);
- }
- /* fine modifica simo */
- /*if(strlen(trim($articolo->getArticolocorrelato1())) > 0){
- $articoloTransfert = ArticoliQuery::create()
- ->filterByCodportale($articolo->getCodportale())
- ->filterByCodlaboratorio($articolo->getCodlaboratorio())
- ->filterByVisualizzabile(0)
- ->filterByCodarticolo($articolo->getArticolocorrelato1())
- ->findOne($con); */
- if (!empty($articoloTransfert)) {
- // Listino personalizzato fotografo
- //if ($legatoFotografo == 1) {
- $applicaListinoFotografo = $utente->getCodportale() == "rikorda" ? ($utente->getFkruolo() == Account_Service::SHOP_ROLE) : ($legatoFotografo == 1);
- //if( $utente->getFkruolo() == Account_Service::SHOP_ROLE ){
- if( $applicaListinoFotografo ){
- $listinoTransfert = ListiniQuery::create()
- ->filterByCodarticolo($articoloTransfert->getCodarticolo())
- ->filterByCodportale($articoloTransfert->getCodportale())
- ->filterByCodlaboratorio($articoloTransfert->getCodlaboratorio())
- ->filterByCodlistino($fotografo->getCodpersonalizzato())
- ->filterByCodpersonalizzato(0)
- ->findOne($con);
- }
- // Listino personalizzato laboratorio
- if (empty($listinoTransfert)) {
- $listinoTransfert = ListiniQuery::create()
- ->filterByCodarticolo($articoloTransfert->getCodarticolo())
- ->filterByCodportale($articoloTransfert->getCodportale())
- ->filterByCodlaboratorio($articoloTransfert->getCodlaboratorio())
- ->filterByCodlistino(0)
- ->filterByCodpersonalizzato(0)
- ->findOne($con);
- }
- // Listino personalizzato portale
- if (empty($listinoTransfert)) {
- $listinoTransfert = ListiniQuery::create()
- ->filterByCodarticolo($articoloTransfert->getCodarticolo())
- ->filterByCodportale($articoloTransfert->getCodportale())
- ->filterByCodlaboratorio(0)
- ->filterByCodlistino(0)
- ->filterByCodpersonalizzato(0)
- ->findOne($con);
- }
- }
- //}
- $articoloTransfertMap = array('desArticolo' => '', 'prezzo' => '0');
- if (!empty($articoloTransfert)) {
- $articoloTransfertMap['desArticolo'] = $articoloTransfert->getDesarticolo();
- $articoloTransfertMap['prezzo'] = empty($listinoTransfert) ? '0' : (string)$listinoTransfert->getPrezzo1();
- }
- $articoloOut->setArticoloTransfert($articoloTransfertMap);
- //*************************************
- // IMPOSTAZIONE ARTICOLO TRANSFERT FINE
- //*************************************
- // Calcolo listino
- $listino = null;
- // Listino personalizzato fotografo
- //if (($utente->getLegatofotografo() == 1) && (count($listiniFotografo) > 0)) {
- $applicaListinoFotografo = $utente->getCodportale() == "rikorda" ? ($utente->getFkruolo() == Account_Service::SHOP_ROLE) : ($legatoFotografo == 1);
- if ($applicaListinoFotografo && (count($listiniFotografo) > 0)) {
- foreach ($listiniFotografo as $listinoFotografo) {
- if ($listinoFotografo->getCodarticolo() == $articolo->getCodarticolo()) {
- $listino = $listinoFotografo;
- break;
- }
- }
- }
- // Listino laboratorio
- if (empty($listino) && (count($listiniLaboratorio) > 0)) {
- foreach ($listiniLaboratorio as $listinoLaboratorio) {
- if ($listinoLaboratorio->getCodarticolo() == $articolo->getCodarticolo()) {
- $listino = $listinoLaboratorio;
- break;
- }
- }
- }
- // Listino portale
- if (empty($listino) && (count($listiniPortale) > 0)) {
- foreach ($listiniPortale as $listinoPortale) {
- if ($listinoPortale->getCodarticolo() == $articolo->getCodarticolo()) {
- $listino = $listinoPortale;
- break;
- }
- }
- }
- // LISTINO NON TROVATO GENERA ERRORE
- if (empty($listino)) {
- throw new Exception("Listino non presente per portale: " . $utente->getCodportale() . " username: "
- . $utente->getUsername() . " password: " . $utente->getPassword()
- . " articolo: " . $articolo->getCodarticolo());
- }
- $listinoMap = array('codListino' => (string)$listino->getCodlistino(), 'codPortale' => $listino->getCodportale(),
- 'codLaboratorio' => (string)$listino->getCodlaboratorio(),
- 'codPersonalizzato' => (string)$listino->getCodpersonalizzato(), 'codArticolo' => (string)$listino->getCodarticolo(),
- 'prezzo1' => "" . (float)$listino->getPrezzo1(), 'quantita1' => "" . (int)$listino->getQuantita1(),
- 'prezzo2' => "" . (float)$listino->getPrezzo2(), 'quantita2' => "" . (int)$listino->getQuantita2(),
- 'prezzo3' => "" . (float)$listino->getPrezzo3(), 'quantita3' => "" . (int)$listino->getQuantita3(),
- 'prezzo4' => "" . (float)$listino->getPrezzo4(), 'quantita4' => "" . (int)$listino->getQuantita4(),
- 'prezzo5' => "" . (float)$listino->getPrezzo5(), 'quantita5' => "" . (int)$listino->getQuantita5());
- $articoloOut->setListino($listinoMap);
- // CAMPAGNE PROMOZIONALI - MAR 2012
- if (array_key_exists($articolo->getCodarticolo(), $listiniCampagneMap)) {
- $listinoPromozionale = $listiniCampagneMap[$articolo->getCodarticolo()];
- $articoloOut->setListinoPromozionale($listinoPromozionale);
- }
- // FINE CAMPAGNE PROMOZIONALI
- if (!array_key_exists($articolo->getFktiposervizio(), $articoliServiziMap)) {
- $articoliMap = array($articolo->getCodarticolo() => $articoloOut->__toString());
- $articoliServiziMap[$articolo->getFktiposervizio()] = $articoliMap;
- } else {
- $articoliMap = $articoliServiziMap[$articolo->getFktiposervizio()];
- $articoliMap[$articolo->getCodarticolo()] = $articoloOut->__toString();
- $articoliServiziMap[$articolo->getFktiposervizio()] = $articoliMap;
- }
- }
- $output->setServicesArticles($articoliServiziMap);
- $output->setStatusMessage(GetAllArticoliResponse::STATUS_OK);
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString());
- $output->setStatusMessage(GetAllArticoliResponse::STATUS_SERVER_ERROR, $e->getMessage());
- }
- $this->logger->log(__FILE__, __LINE__, "Execution Time: " . (microtime(true) - $time_start) . " Sec", Zend_Log::DEBUG); /*STOP TIME LOG*/
- // $strout = $output->__toString();
- // $strout = base64_encode(gzcompress(Zend_Json::encode($strout)));
- //controllo versione per client più vecchi di 1.5.11*, a loro $strout non va compresso
- $version = ClientversionQuery::create()->filterByCodportale($portale->getCodportale())->filterByUsername($username)->select("Version")->findOne($con);
- if (substr($version, 0, 5) === "1.5.9" || substr($version, 0, 6) === "1.5.10") {
- return $output->getServicesArticles();
- } else {
- $strout = utf8_decode($output->toXml());
- $md5 = md5($strout);
- $strout = base64_encode(gzcompress($strout));
- return array('md5' => $md5, 'data' => $strout);
- }
- }
- /**
- * @param string $codPortale
- * @param string $codLaboratorio
- * @param string $codFotografo
- * @param string $username
- * @param string $password
- * @return GetUtenteFotografoResponse
- */
- public function getUtenteFotografo($codPortale, $codLaboratorio, $codFotografo, $username, $password)
- {
- $ret = new GetUtenteFotografoResponse();
- $loginStatus = $this->login($codPortale, $username, $password, false);
- // Login fallito
- if ($loginStatus != self::LOGIN_STATUS_OK) {
- $ret->setStatusMessage(GetUtenteFotografoResponse::STATUS_USER_NOT_FOUND, array($codPortale, $username, $password));
- return $ret;
- }
- try {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $utente = UtentiQuery::create()->filterByCodportale($codPortale)->filterByUsername($username)->findOne($con);
- if (empty($utente)) {
- $utente = UtentiQuery::create()->filterByCodportaleold($codPortale)->filterByUsername($username)->findOne($con);
- }
- $fotografo = UtentiQuery::create()
- ->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getCodlaboratorio())
- ->filterByCodfotografo($utente->getCodfotografo())
- ->filterByTipo('F')
- ->findOne($con);
- if (empty($fotografo)) {
- $ret->setStatusMessage(GetUtenteFotografoResponse::STATUS_FOTOGRAFO_NOT_FOUND,
- array($utente->getCodportale(), $utente->getCodlaboratorio(), $utente->getCodfotografo()));
- return $ret;
- }
- $ret->setRagioneSociale($fotografo->getRagionesociale());
- $ret->setIndirizzo($fotografo->getIndirizzo());
- $ret->setCap($fotografo->getCap());
- $ret->setCitta($fotografo->getCitta());
- $ret->setProvincia($fotografo->getProvincia());
- $ret->setNazione($fotografo->getNazione());
- $ret->setStatusMessage(GetUtenteFotografoResponse::STATUS_OK);
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
- $ret->setStatusMessage(GetUtenteFotografoResponse::STATUS_SERVER_ERROR, $e->getMessage());
- }
- return $ret;
- }
- /**
- * @throws Exception
- * @param string $codPortale
- * @param string $codLaboratorio
- * @param string $tipoUtente
- * @param string|int $modalita
- * @param string $codAgente
- * @param string $md5
- * @return string
- */
- public function getXmlServizi($codPortale, $codLaboratorio, $tipoUtente, $modalita, $codAgente = "", $md5 = "")
- {
- $codLaboratorio = (int)$codLaboratorio;
- /*
- $tipoUtente = 'U';
- $modalita = 1;
- // I parametri sono dinamici, se sono 5 il terzo diventa il codice agente
- $params = func_get_args();
- $nParam = count($params);
- if($nParam > 4){
- $tipoUtente = $params[3];
- $modalita = (int) $params[4];
- }
- else{
- if($nParam > 2){
- $tipoUtente = $params[2];
- }
- if($nParam > 3){
- $modalita = (int) $params[3];
- }
- }
- */
- $this->logger->log(__FILE__, __LINE__, "getXmlServizi PORTALE: $codPortale LABO: $codLaboratorio TIPO: $tipoUtente modalita: $modalita");
- //-------------------------
- $ftpHome = empty($this->alternativeFtpHome) ? self::FTP_HOME : $this->alternativeFtpHome;
- //-- TEST-LUX: solo per test serve per confrontare il file in cache generato del vecchio fototaxi con l'attuale
- $testFileContent = "";
- $fileCacheName = "{$ftpHome}/cache/servizi_{$codPortale}_{$codLaboratorio}_{$tipoUtente}_{$modalita}";
- if (is_file($fileCacheName)) {
- $fileContent = file_get_contents($fileCacheName);
- if ($fileContent === FALSE) {
- $this->logger->log(__FILE__, __LINE__, "Error reading from $fileCacheName cache file", Zend_Log::ERR);
- } else {
- //-- TEST-LUX
- $testFileContent = $fileContent;
- //return $fileContent;
- }
- }
- $xml = ''; // Output
- //--------------------------
- // CONVERSIONE PORTALE
- //--------------------------
- try {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $cp = ConversioneportaliQuery::create()
- ->filterByCodportaleold($codPortale)
- ->filterByCodlaboratorioold(0)
- ->filterByCodfotografoold(0)
- ->filterByCodgruppoold('')
- ->select(array('Codportaleold', 'Codportalenew'))
- ->findOne($con);
- if (!empty($cp)) {
- $this->logger->log(__FILE__, __LINE__, "CONVERSIONE -> Portale Vecchio: $codPortale Portale Nuovo: " . $cp['Codportalenew']);
- $codPortale = $cp['Codportalenew'];
- }
- //-------------------------------
- // Lista servizi
- $ls = ServiziQuery::create()
- ->filterByCodportale($codPortale)
- ->filterByOrdinabilefototaxi('1')
- ->addJoinObject(new Join(array(ServiziPeer::CODPORTALE, ServiziPeer::CODSERVIZIO),
- array(ServizilaboratoriPeer::CODPORTALE, ServizilaboratoriPeer::CODSERVIZIO),
- Criteria::LEFT_JOIN))
- ->withColumn('ServiziLaboratori.Codlaboratorio', 'Codlaboratorio')
- ->where("ServiziLaboratori.CodLaboratorio = $codLaboratorio")
- ->find($con);
- //-------------------------------
- if ($ls->count() > 0) {
- $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
- $xml .= '<' . 'SERVICES' . '>';
- $articoliQuery = ArticoliQuery::create()
- ->filterByCodportale($codPortale)
- ->filterByCodlaboratorio($codLaboratorio)
- ->condition('cond1', "Articoli.Flagtipoutente='B'")
- ->condition('cond2', 'Articoli.Flagtipoutente=?', $tipoUtente)
- ->where(array('cond1', 'cond2'), 'or');
- /***********************************************************************************
- * ' per modalita mista devono essere scaricati tutti gli articoli
- * ' per tutte le altre devono essere scaricati articoli con flag=0 o flag=modalita
- ***********************************************************************************/
- if ($modalita == 1 || $modalita == 2) {
- $articoliQuery = $articoliQuery
- ->condition('cond3', 'Articoli.Flagmodalita=0')
- ->condition('cond4', 'Articoli.Flagmodalita=?', $modalita)
- ->where(array('cond3', 'cond4'), 'or');
- }
- $app = $articoliQuery->select(array('Codarticolo'))->find($con)->toArray();
- $encThumb = '';
- foreach ($ls as $service) {
- $service = $this->__toService($service);
- //------------------------------------------------------------------------
- // SCRIVE NEL XML SOLO I SERVIZI PER I QUALI SONO STATI CARICATI ARTICOLI
- //-------------------------------------------------------------------------
- $haveArticoli = AlberoQuery::create()
- ->filterByCodportale($codPortale)
- ->where("SUBSTRING(Albero.Codalbero, 1, 2) = ?", $service->getCodservizio())
- ->where("( LENGTH(Albero.Codalbero=8) || LENGTH(Albero.Codalbero)=10 )")
- ->where('Albero.Codarticolo IN ?', $app)
- ->select(array('Codalbero'))->count($con);
- //--------------------------------------
- if (($haveArticoli > 0) || ($service->getFktiposervizio() == 'SS')) {
- // Reperimento stream thumbnail
- $thumb = $service->getThumb();
- if (!empty($thumb)) {
- $thumb = stream_get_contents($service->getThumb());
- }
- // QUESTO IF SERVE SOLO IN AMBIENTE DI TEST, POICHE I DATASET XML POSSONO CONTENERE SOLO
- // STRINGHE BASE64
- // Conversione da base64 (solo in ambiente di Test)
- if (base64_encode(base64_decode($thumb)) === $thumb) {
- $thumb = base64_decode($thumb);
- }
- if (strlen($thumb) > 0) {
- $encThumb = base64_encode($thumb);
- }
- $xml .= '<SERVICE CODE="' . $service->getCodservizio() . '">';
- $xml .= '<TYPE>' . $service->getFktiposervizio() . '</TYPE>';
- $xml .= (strlen(trim($service->getTitolo())) > 0)
- ? '<TITLE><![CDATA[' . $service->getTitolo() . ']]></TITLE>'
- : '<TITLE/>';
- $xml .= (strlen(trim($service->getDescrizione())) > 0)
- ? '<DESCRIPTION><![CDATA[' . $service->getDescrizione() . ']]></DESCRIPTION>'
- : '<DESCRIPTION/>';
- $xml .= (strlen($thumb) > 0) ? '<THUMB>' . $encThumb . '</THUMB>' : '<THUMB/>';
- $xml .= '</SERVICE>';
- }
- } // Fine foreach $ls as $service
- $xml .= '</SERVICES>';
- } // FINE if $ls->count() > 0
- //-- TEST-LUX: commentare
- if (!empty($testFileContent) && strcmp($xml, $testFileContent) !== 0) {
- $this->logger->log(__FILE__, __LINE__, "ERRORE getXmlServizi differenza con file di cache: $codPortale - $codLaboratorio - $tipoUtente - $modalita - $codAgente - $md5", Zend_Log::DEBUG);
- }
- /* TEST-LUX: scommentare
- // Creazione cache
- $cached = file_put_contents($fileCacheName, $xml, LOCK_EX);
- if($cached === false){
- $this->logger->log(__FILE__, __LINE__, "Scrittura su cache file $fileCacheName fallita", Zend_Log::ERR);
- }
- */
- $serverMd5 = md5(utf8_decode($xml));
- $this->logger->log(__FILE__, __LINE__, "SERVIZI -> MD5 server: $serverMd5 MD5Client $md5", Zend_Log::INFO);
- if ($md5 == $serverMd5) {
- $xml = "";
- }
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
- throw $e;
- }
- return $xml;
- }
- /**
- * @param string $codPortale
- * @param string $username
- * @param string $password
- * @param bool $clientCall
- * @return int lo status della login (OK=0)
- */
- public function login($codPortale, $username, $password, $clientCall = true)
- {
- $status = self::LOGIN_STATUS_USER_NOT_FOUND;
- if (in_array($codPortale, ExternalService::$externalPortals) && $clientCall) {
- try {
- $status = ExternalService::logIn($codPortale, $username, $password);
- if ($status != ExternalService::EXTERNAL_LOGIN_OK) {
- // Autenticazione fallita, codice di errore specifico
- return $status;
- }
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, "Errore autenticazione esterna: " . $e->getMessage());
- }
- }
- // Portale senza articoli
- // Autenticazione portale
- $accountService = new Account_Service();
- $utente = $accountService->loginPostali($codPortale, $username, $password, null, null, false, true);
- return $this->_accountServiceLoginStatusConvertion($utente);
- }
- /**
- * @throws Exception
- * @param $codPortale
- * @param $username
- * @param $password
- * @param bool $verifyLogin
- * @param bool $downloadNewPromotions
- * @return GetCliserResponse
- */
- public function getCliser($codPortale, $username, $password, $verifyLogin = true, $downloadNewPromotions = true)
- {
- $ret = new GetCliserResponse();
- try {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_WRITE);
- $utente = UtentiQuery::create()->filterBycodPortale($codPortale)->filterByUsername($username)->findOne($con);
- // Gestione codportaleold
- if (empty($utente)) {
- $utente = UtentiQuery::create()->filterBycodPortaleOld($codPortale)->filterByUsername($username)->findOne($con);
- }
- if (empty($utente)) {
- $this->logger->log(__FILE__, __LINE__, "Utente non trovat: codPortale=$codPortale, username=$username", Zend_Log::INFO);
- throw new Exception("Utente non trovato");
- }
- // Fotografo, laboratorio, portale
- $fotografo = FotografiQuery::create()->filterByCodportale($utente->getcodPortale())
- ->filterBycodLaboratorio($utente->getcodLaboratorio())
- ->filterBycodFotografo($utente->getcodFotografo())
- ->findOne($con);
- $laboratorio = LaboratoriQuery::create()->filterBycodPortale($utente->getcodPortale())
- ->filterBycodLaboratorio($utente->getcodLaboratorio())
- ->findOne($con);
- $portale = PortaliQuery::create()->filterBycodPortale($utente->getcodPortale())->findOne($con);
- // Dati anagrafici
- $ret->setTel($utente->getTel() == null ? "" : $utente->getTel());
- $ret->setCitta($utente->getCitta() == null ? "" : $utente->getCitta());
- $ret->setIndirizzo($utente->getIndirizzo() == null ? "" : $utente->getIndirizzo());
- $ret->setProvincia($utente->getProvincia() == null ? "" : $utente->getProvincia());
- $ret->setRagioneSociale($utente->getRagionesociale() == null ? "" : $utente->getRagionesociale());
- $ret->setNazione($utente->getNazione() == null ? "" : $utente->getNazione());
- $ret->setMail($utente->getMail() == null ? "" : $utente->getMail());
- $ret->setFax($utente->getFax() == null ? "" : $utente->getFax());
- $ret->setPiva($utente->getPiva() == null ? "" : $utente->getPiva());
- $ret->setCap($utente->getCap() == null ? "" : $utente->getCap());
- // Inidirizzo sito e mailto
- if ($utente->getLegatofotografo() == 0) {
- $ret->setSitoWeb(strval($portale->getSitoweb()));
- $ret->setMailTo(strval($portale->getMail()));
- } else {
- $ret->setSitoWeb(strval($fotografo->getSitoweb()) == null ? "" : strval($fotografo->getSitoweb()));
- $ret->setMailTo(strval($fotografo->getMail()) == null ? "" : strval($fotografo->getMail()));
- }
- // Dati ordini
- $ret->setCodFotografo(strval($utente->getcodFotografo()) == null ? "" : strval($utente->getcodFotografo()));
- $ret->setCodLabo(strval($utente->getcodLaboratorio()) == null ? "" : strval($utente->getcodLaboratorio()));
- $ret->setUsername(strval($utente->getUsername()) == null ? "" : strval($utente->getUsername()));
- $ret->setPassword(strval($utente->getPassword()) == null ? "" : strval($utente->getPassword()));
- $ret->setTipo(strval($utente->getTipo()) == null ? "" : strval($utente->getTipo()));
- // Per fotografi, consegna sempre 'F'
- $ret->setConsegna(($utente->getTipo() == 'U') ? $utente->getConsegna() : 'F');
- $ret->setTipoPortale(strval($portale->getTipoportale()));
- $ret->setArtInProp(strval($laboratorio->getartInPropClient()));
- $ret->setMaxOrdine(strval(($utente->getmaxOrdineAutomatico() == 0) ? $fotografo->getmaxOrdineAutomatico() : $utente->getmaxOrdineAutomatico()));
- // Fido residuo
- $accountService = new Account_Service();
- $ret->setFidoResiduo(strval($accountService->getFidoResiduo($utente->getIdutente())));
- $ret->setPrimoOrdine(($utente->getHaveordini() == 0) ? '1' : '0');
- $ret->setPercScontoPrimoOrdine(strval($portale->getpercScontoPrimoOrdine()));
- $ret->setImpMinOrdine(strval($portale->getimpMinimoOrdine()));
- $ret->setQtaMinOrdine(strval($portale->getQtminimaordine()));
- // Dati client
- $ret->setTimeNextDownload('0');
- $ret->setTimeNextDownloadNew(strval($portale->getAggclient()));
- if (($laboratorio->getClientcompressionemin() == 0) || ($laboratorio->getClientcompressionemax() == 0)) {
- $ret->setMinQualitySpeed(strval($portale->getClientcompressionemin()));
- $ret->setMaxQualitySpeed(strval($portale->getClientcompressionemax()));
- } else {
- $ret->setMinQualitySpeed(strval($laboratorio->getClientcompressionemin()));
- $ret->setMaxQualitySpeed(strval($laboratorio->getClientcompressionemax()));
- }
- $ret->setControlloFidoFotografo(strval($portale->getfotografoSoggettoFido()));
- $ret->setRifiutoAuto(strval($fotografo->getFlageliminaordini()));
- $ret->setCodPortale(strval($utente->getcodPortale()) == null ? "" : strval($utente->getcodPortale()));
- // Cambiadestinazione e modalbrowser
- $cambia_destinazione = ($utente->getLegatofotografo() == 1 && (strlen($utente->getAmminfototaxi()) > 0 && $utente->getAmminfototaxi() === '0')) ? '0' : '1';
- /* per fotoservice */
- if ($portale->gettipoPortale() == 'M' && strlen(trim(strval($utente->getcodGruppo()))) > 0) {
- $dg = DominigruppiQuery::create()->filterByCodportale($utente->getCodportale())->filterByCodgruppo($utente->getCodgruppo())->findOne($con);
- if (!empty($dg)) {
- $cambia_destinazione = $dg->getModalitapagamento() == 'M' ? '1' : '0';
- }
- }
- /* fine */
- /* modifica simo: postale rikorda non vede pulsante cambia destinazione */
- if ($portale->getCodportale() == "rikorda") {
- $cambia_destinazione = '0';
- }
- /* fine */
- $ret->setCambiaDestinazione($cambia_destinazione);
- // TODO : filtro compressione skipped
- $ret->setModalBrowser($portale->getModalbrowser() ? '1' : '0');
- $promo_collegate = array();
- //--------------------------------------------------
- $downloadCampagne = false;
- $clientVersion = ClientversionQuery::create()->filterByCodportale($utente->getcodPortale())->filterByUsername($utente->getUsername())->findOne($con);
- if (!empty($clientVersion)) {
- $paramVersion = explode(".", $clientVersion->getVersion());
- $major = $paramVersion[0];
- $minor = $paramVersion[1];
- $build = $paramVersion[2];
- if ($major == 1 && ($minor > 5 || ($minor == 5 && $build >= 109))) {
- $downloadCampagne = true;
- }
- }
- $promozioni = array();
- if ($downloadCampagne) {
- // CAMPAGNE PROMOZIONALI - MARZO 2012
- $now = new DateTime();
- $campagne = CampagneQuery::create()
- ->filterByCodiceportale($utente->getCodportale())
- ->where("Campagne.Datainizio <= ?", $now)
- ->where("Campagne.Datafine >= ?", $now)
- ->where("Campagne.Tipo in ?", array('ALL'))
- ->find($con);
- if ($campagne->count() > 0) {
- foreach ($campagne as $campagna) {
- $escluso = EsclusionefotograficampagneQuery::create()
- ->filterByCodportale($utente->getcodPortale())
- ->filterByCodlaboratorio($utente->getCodlaboratorio())
- ->filterByCodfotografo($utente->getCodfotografo())
- ->where("Esclusionefotograficampagne.Codcampagna = ?",
- $campagna->getCodicecampagna())
- ->orWhere("EsclusioneFotografiCampagne.Codcampagna = ''")
- ->findOne($con);
- /* esclusione di
- 1. campagne x tipo utente diverso da quello dell'utente finale
- 2. campagne con applicabilita per tema => solo online
- 3. campagne con applicabilita software != FOTOTAXIOLD
- */
- $promoCampagna = $campagna->getPromozione();
- if (empty($escluso) &&
- !empty($promoCampagna) &&
- $promoCampagna->isApplicabileUtente($utente) &&
- $promoCampagna->getCheckTemi() == 0 &&
- $promoCampagna->isApplicabileClient('FOTOTAXIOLD') &&
- $promoCampagna->isApplicabileFotografo($utente)
- ) {
- $promozione = $promoCampagna->toArray();
- /*$promozione = PromozioniQuery::create()
- ->filterByCodportale($campagna->getCodiceportale())
- ->filterByCodpromozione($campagna->getCodicepromozione())
- ->findOne($con)->toArray();
- $isApplicabileClient = $promozione["Checkclients"] == 0;
- if( $promozione["Checkclients"] == 1 ){
- $promozioneClients = PromozioniclientsQuery::create()
- ->filterByCodportale($campagna->getCodiceportale())
- ->filterByCodpromozione($campagna->getCodicepromozione())
- ->find($con);
- foreach($promozioneClients as $promozioneClient){
- if( $promozioneClient->getSoftware() == 'FOTOTAXIOLD'){
- $isApplicabileClient = true;
- break;
- }
- }
- }
- $isApplicabileFotografo = true;
- if( $utente->getTipo() == 'F' && $promozione["Tipofotografo"] != 'all' && $promozione["Tipofotografo"] != $fotografo->getTipofotografo() ){
- $isApplicabileFotografo = false;
- }*/
- /* esclusione di
- 1. campagne x tipo utente diverso da quello dell'utente finale
- 2. campagne con applicabilita per tema => solo online
- 3. campagne con applicabilita software != FOTOTAXIOLD
- */
- /*if ( ( $promozione["Tipoutente"] == 'B' || $promozione["Tipoutente"] == $utente->getTipo() ) &&
- $promozione["Checktemi"] == 0 && $isApplicabileClient && $isApplicabileFotografo) {*/
- $promozione["QtaResidue"] = 0;
- $promozione["ValoreResiduo"] = 0;
- /*$prom_obj= new __Promozioni();
- $prom_obj->setCod($promozione->getCodpromozione());
- $prom_obj->setDescrizione($promozione->getDescrizione());
- $prom_obj->setClasse($promozione->getclasseArticoli());
- $prom_obj->setPerc(strval($promozione->getPercsconto()));
- $prom_obj->setFlagTipoPromozione(strval($promozione->getFlagtipopromozione()));
- // -----
- $prom_obj->setQta('0');
- $prom_obj->setValore('0');
- // -----
- $prom_obj->setImpMin(strval($promozione->getImpminimoordine()));
- $prom_obj->setFlagPagaTransfert(strval($promozione->getPagatransfert()));
- $prom_obj->setQtaApplicaSconto(strval($promozione->getQtaapplicasconto()));
- $prom_obj->setArticoli($this->__jsonToString($promozione->getListaarticoli()));
- $prom_obj->setQtaMin(strval($promozione->getQtaminimaordine()));
- $prom_obj->setCondClassi($promozione->getCondclassearticoli());
- $prom_obj->setCondArticoli($this->__jsonToString($promozione->getCondListaarticoli()));
- $prom_obj->setCondRicorsiva(strval($promozione->getCondricorsiva()));
- $prom_obj->setCodPromozioneCollegata($promozione->getCodpromozionecollegata());
- $prom_obj->setProssimoOrdine(strval($promozione->getProssimoordine()));
- $prom_obj->setQtaPromo(strval($promozione->getQta()));
- $prom_obj->setPriorita(strval($promozione->getPriorita()));
- if( $promozione->getCodpromozionecollegata() ){
- $promo_collegate[] = $promozione->getCodpromozionecollegata();
- }
- //$ret->addPromozione($prom_obj);*/
- $promozioni[] = $promozione;
- //}
- }
- }
- }
- }
- // @@since here tested
- // Lista promozioni associate utente
- $credits = $this->_getCredits($con, $portale, $utente);
- // Log dei credits
- $logCredits = "Credits: [";
- $n = count($credits);
- foreach ($credits as $i => $credit) {
- $logCredits .= $credit;
- if ($i < $n - 1) {
- $logCredits .= ", ";
- }
- if (!$downloadNewPromotions &&
- (($credit->getFlagtipopromozione() == 5 || $credit->getFlagtipopromozione() == 6) ||
- ($credit->getCondlistaarticoli() != null && $credit->getCondlistaarticoli() != "") ||
- ($credit->getCondclassearticoli() != null && $credit->getCondclassearticoli() != "") ||
- ($credit->getListaarticoli() != null && $credit->getListaarticoli() != "") ||
- $credit->getProssimoordine() != 0 || $credit->getQtaminimaordine() > 0 ||
- ($credit->getCodpromozionecollegata() != null && $credit->getCodpromozionecollegata() != "")
- )
- ) {
- continue;
- }
- $credit = $this->__toPromo($credit);
- $promozione = $credit->toArray();
- $promozione["QtaResidue"] = $credit->getQtaResidue();
- $promozione["ValoreResiduo"] = $credit->getValoreResiduo();
- /*$prom_obj= new __Promozioni();
- $prom_obj->setCod($credit->getCodpromozione());
- $prom_obj->setDescrizione($credit->getDescrizione());
- $prom_obj->setClasse($credit->getClassearticoli());
- $prom_obj->setPerc(strval($credit->getPercsconto()));
- $prom_obj->setFlagTipoPromozione(strval($credit->getFlagtipopromozione()));
- $prom_obj->setQta(strval($credit->getQtaResidue()));
- $prom_obj->setValore(strval($credit->getValoreResiduo()));
- $prom_obj->setImpMin(strval($credit->getImpminimoordine()));
- //modifiche 02_2005------------------------------------------------------
- $prom_obj->setFlagPagaTransfert(strval($credit->getPagatransfert()));
- //-----------------------------------------------------------------------
- $prom_obj->setQtaApplicaSconto(strval($credit->getQtaapplicasconto()));
- $prom_obj->setArticoli($this->__jsonToString($credit->getListaarticoli()));
- $prom_obj->setQtaMin(strval($credit->getQtaminimaordine()));
- $prom_obj->setCondClassi($credit->getCondclassearticoli());
- $prom_obj->setCondArticoli($this->__jsonToString($credit->getCondListaarticoli()));
- $prom_obj->setCondRicorsiva(strval($credit->getCondricorsiva()));
- $prom_obj->setCodPromozioneCollegata($credit->getCodpromozionecollegata());
- $prom_obj->setProssimoOrdine(strval($credit->getProssimoordine()));
- $prom_obj->setQtaPromo(strval($credit->getQta()));
- $prom_obj->setPriorita(strval($credit->getPriorita()));
- */
- if ($credit->getCodpromozionecollegata()) {
- $promo_collegate[] = $credit->getCodpromozionecollegata();
- }
- //$ret->addPromozione($prom_obj);
- $promozioni[] = $promozione;
- }
- $logCredits .= "]";
- $promozioni_tmp = array();
- foreach ($promozioni as $promozione) {
- $promozioni_tmp[] = $promozione["Priorita"];
- }
- array_multisort($promozioni_tmp, SORT_ASC, $promozioni);
- foreach ($promozioni as $promozione) {
- $prom_obj = new __Promozioni();
- $prom_obj->setCod($promozione["Codpromozione"]);
- $prom_obj->setDescrizione($promozione["Descrizione"]);
- $prom_obj->setClasse($promozione["Classearticoli"]);
- $prom_obj->setPerc(strval($promozione["Percsconto"]));
- $prom_obj->setFlagTipoPromozione(strval($promozione["Flagtipopromozione"]));
- $prom_obj->setQta(strval($promozione["QtaResidue"]));
- $prom_obj->setValore(strval($promozione["ValoreResiduo"]));
- $prom_obj->setImpMin(strval($promozione["Impminimoordine"]));
- //modifiche 02_2005------------------------------------------------------
- $prom_obj->setFlagPagaTransfert(strval($promozione["Pagatransfert"]));
- //-----------------------------------------------------------------------
- $prom_obj->setQtaApplicaSconto(strval($promozione["Qtaapplicasconto"]));
- $prom_obj->setArticoli($this->__jsonToString($promozione["Listaarticoli"]));
- $prom_obj->setQtaMin(strval($promozione["Qtaminimaordine"]));
- $prom_obj->setCondClassi($promozione["Condclassearticoli"]);
- $prom_obj->setCondArticoli($this->__jsonToString($promozione["Condlistaarticoli"]));
- $prom_obj->setCondRicorsiva(strval($promozione["Condricorsiva"]));
- $prom_obj->setCodPromozioneCollegata($promozione["Codpromozionecollegata"]);
- $prom_obj->setProssimoOrdine(strval($promozione["Prossimoordine"]));
- $prom_obj->setQtaPromo(strval($promozione["Qta"]));
- $ret->addPromozione($prom_obj);
- }
- if (!empty($promo_collegate)) {
- $collegate = PromozioniQuery::create()
- ->filterByCodportale($portale->getCodportale())
- ->filterByCodpromozione($promo_collegate, Criteria::IN)
- ->find($con);
- foreach ($collegate as $collegata) {
- $prom_obj = new __Promozioni();
- $prom_obj->setCod($collegata->getCodpromozione());
- $prom_obj->setDescrizione($collegata->getDescrizione());
- $prom_obj->setClasse($collegata->getClassearticoli() != "" ? $collegata->getClassearticoli() : "");
- $prom_obj->setPerc(strval($collegata->getPercsconto()));
- $prom_obj->setFlagTipoPromozione(strval($collegata->getFlagtipopromozione()));
- $prom_obj->setQta(strval($collegata->getQta()));
- $prom_obj->setValore(strval($collegata->getValore()));
- $prom_obj->setImpMin(strval($collegata->getImpminimoordine()));
- //modifiche 02_2005------------------------------------------------------
- $prom_obj->setFlagPagaTransfert(strval($collegata->getPagatransfert()));
- //-----------------------------------------------------------------------
- $prom_obj->setQtaApplicaSconto(strval($collegata->getQtaapplicasconto()));
- $prom_obj->setArticoli($this->__jsonToString($collegata->getListaArticoli()));
- $prom_obj->setQtaMin(strval($collegata->getQtaminimaordine()));
- $prom_obj->setCondClassi($collegata->getCondclassearticoli());
- $prom_obj->setCondArticoli($this->__jsonToString($collegata->getCondListaArticoli()));
- $prom_obj->setCondRicorsiva(strval($collegata->getCondricorsiva()));
- $prom_obj->setCodPromozioneCollegata($collegata->getCodpromozionecollegata());
- $ret->addPromozioneCollegata($prom_obj);
- }
- }
- $this->logger->log(__FILE__, __LINE__, $logCredits);
- // Dimensione immagini basse risoluzione
- $config = Zend_Registry::get('Redarea_Configuration');
- $ret->setLresMaxSize($config->image->web->max->size);
- // Fototaxi-web
- $ret->setFototaxiWeb($portale->getFototaxiweb() ? '1' : '0');
- $ret->setStatusMessage(GetCliserResponse::STATUS_OK);
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
- $ret->setStatusMessage(GetCliserResponse::STATUS_SERVER_ERROR, array($e->getMessage()));
- }
- //D:\projects\rikorda_old\front\src\com\pytaxi\util\XmlRpcMethods.java, porting fino a linea
- return $ret;
- }
- /**
- * @param string $codPortale
- * @param string $username
- * @param string $password
- * @param string $version
- * @param string $release
- * @return GetCliser2Response
- */
- public function getCliser2($codPortale, $username, $password, $version, $release = null)
- {
- $paramVersion = explode(".", $version);
- $major = $paramVersion[0];
- $minor = $paramVersion[1];
- $build = $paramVersion[2];
- $downloadNewPromotions = false;
- // download nuove promozioni se versione fototaxi è >= 1.5.139
- //if( $major == 1 && ($minor>5 || ($minor == 5 && $build >= 139)) ){
- if ($major == 1 && ($minor > 5 || ($minor == 5 && $build >= 108))) {
- $downloadNewPromotions = true;
- }
- $response = new GetCliser2Response();
- try {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_WRITE);
- $sql = "REPLACE INTO ClientVersion (codPortale, username, version, rel) VALUES ('" . $codPortale . "', '" . $username . "', '" . $version . "', '" . $release . "')";
- $stmt = $con->prepare($sql);
- $stmt->execute();
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
- $response->setStatusMessage(GetCliser2Response::STATUS_SERVER_ERROR, array($e->getMessage()));
- return $response;
- }
- //$ret = $this->getCliser($codPortale, $username, $password, true);
- $ret = $this->getCliser($codPortale, $username, $password, true, $downloadNewPromotions);
- $response->fromGetCliserRespoonse($ret);
- $response->setUrlServerPhp('/services/xmlrpc.php');
- $response->setPathUploadPhp('/services/upload_fototaxi.php');
- $response->setStatusMessage($ret->getStatus());
- //$response->setStatusMessage(!$downloadNewPromotions ? GetCliser2Response::STATUS_VERSION_UPG : $ret->getStatus());
- return $response;
- }
- /**
- * Torna una mappa di file solo se il codice md5 e' diverso
- * @param struct|array $params - chiavi:
- * codPortale
- * codLaboratorio (usato solo se username e password sono null)
- * codFotografo (usato solo se username e password sono null)
- * username
- * password
- * md5Logo
- * md5Banner
- * md5Tema
- * lang=it
- * @return GetTemaResponse
- */
- public function getTema($params)
- {
- $ret = new GetTemaResponse();
- //$TEMA = 'theme_' . (array_key_exists('lang', $params) ? $params['lang'] : 'it') . '.zip';
- $codPortale = array_key_exists('codPortale', $params) ? (string)$params['codPortale'] : null;
- $codLaboratorio = array_key_exists('codLaboratorio', $params) ? (string)$params['codLaboratorio'] : null;
- $codFotografo = array_key_exists('codFotografo', $params) ? (string)$params['codFotografo'] : null;
- $codGruppo = array_key_exists('codGruppo', $params) ? (string)$params['codGruppo'] : null;
- $codAgente = array_key_exists('codAgente', $params) ? (string)$params['codAgente'] : null;
- $username = array_key_exists('username', $params) ? (string)$params['username'] : null;
- $password = array_key_exists('password', $params) ? (string)$params['password'] : null;
- $lang = array_key_exists('lang', $params) ? (string)$params['lang'] : null;
- try {
- // Se username e password sono null significa che ancora non mi sono registrato.
- // In questo caso prendo in esame solo portale e se esistono, laboratorio e fotografo
- if (!empty($username) && !empty($password)) {
- $loginStatus = $this->login($codPortale, $username, $password, false);
- if ($loginStatus != self::LOGIN_STATUS_OK) {
- $ret->setStatusMessage(GetTemaResponse::STATUS_USER_NOT_FOUND, array($codPortale, $username, $password));
- return $ret;
- }
- }
- $temaFiles = Fototaxi_UtilsService::getTemaFiles($codPortale, $codLaboratorio, $codFotografo, $codGruppo, $codAgente, $username, $password, $lang);
- if ($temaFiles['notFound'] !== false) {
- $ret->setStatusMessage(GetTemaResponse::STATUS_SERVER_ERROR, array("File not found: " . $temaFiles['notFound']));
- return $ret;
- }
- //LOGO
- $realPath = dirname(APPLICATION_PATH) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR;
- $pathLogo = $realPath . $temaFiles['logo']['path'];
- $LOGO = $temaFiles['logo']['filename'];
- $this->logger->log(__FILE__, __LINE__, "PATH_LOGO: $pathLogo");
- $imgBytes = file_get_contents($pathLogo);
- if (md5(mb_convert_encoding($imgBytes, 'ISO-8859-1')) != $params['md5Logo']) {
- $ret->addWrongMd5File('imgLogo', array($LOGO, new Zend_XmlRpc_Value_Base64(base64_encode($imgBytes))));
- }
- //BANNER
- $pathBanner = $realPath . $temaFiles['banner']['path'];
- $BANNER = $temaFiles['banner']['filename'];
- $this->logger->log(__FILE__, __LINE__, "PATH_BANNER: $pathBanner");
- $imgBytes = file_get_contents($pathBanner);
- if (md5(mb_convert_encoding($imgBytes, 'ISO-8859-1')) != $params['md5Banner']) {
- $ret->addWrongMd5File('imgBanner', array($BANNER, new Zend_XmlRpc_Value_Base64(base64_encode($imgBytes))));
- }
- // TEMA
- $pathThema = $realPath . $temaFiles['tema']['path'];
- $this->logger->log(__FILE__, __LINE__, "PATH_TEMA: $pathThema");
- $imgBytes = file_get_contents($pathThema);
- if (md5(mb_convert_encoding($imgBytes, 'ISO-8859-1')) != $params['md5Tema']) {
- // il tema si chiama sempre theme.zip
- $ret->addWrongMd5File('imgTema', array('theme.zip', new Zend_XmlRpc_Value_Base64(base64_encode($imgBytes))));
- }
- $ret->setStatusMessage(GetTemaResponse::STATUS_OK);
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
- $ret->setStatusMessage(GetTemaResponse::STATUS_SERVER_ERROR, array($e->getMessage()));
- }
- return $ret;
- }
- /**
- * Converte stati di login a servizi esterni in codici di stato di questa classe
- * @param UserItem $accountServiceLoginData
- * @return int
- */
- private function _accountServiceLoginStatusConvertion($accountServiceLoginData)
- {
- $accountServiceLoginStatus = $accountServiceLoginData->getStatus();
- $status = self::LOGIN_STATUS_USER_NOT_FOUND;
- if ($accountServiceLoginStatus > 0) {
- $userData = $accountServiceLoginData->getUser();
- if (($accountServiceLoginStatus == UserItem::STATUS_OK_AND_DISABLED_VIRTUAL_SHOP) && ($userData['Fkruolo'] == Account_Service::USER_ROLE)) {
- $status = self::EXTERNAL_LOGIN_DISABLED_VIRTUAL_SHOP;
- } else {
- $status = self::LOGIN_STATUS_OK;
- }
- } else {
- switch ($accountServiceLoginStatus) {
- case UserItem::STATUS_DISABLED:
- case UserItem::STATUS_INACTIVE:
- $status = self::LOGIN_STATUS_USER_NOT_ACTIVE;
- break;
- case UserItem::STATUS_WRONG_PASSWORD:
- $status = self::LOGIN_STATUS_USER_WRONG_PASS;
- break;
- // Tutti gli altri eventuali casi sono 'not found'
- }
- }
- return $status;
- }
- /**
- * @param PDO $con
- * @param Portali $portale
- * @param Utenti $utente
- * @param int $visibile
- * @return array
- */
- private function _getCredits($con, $portale, $utente, $visibile = 1)
- {
- $creditList = array();
- $coupons = CreditsQuery::create()
- ->filterByCodportale($utente->getcodPortale())
- ->filterByUsername($utente->getUsername())
- ->filterByUtilizzabile(1)
- ->addJoinObject(new Join(array(CreditsPeer::CODPORTALE, CreditsPeer::CODPROMOZIONE),
- array(PromozioniPeer::CODPORTALE, PromozioniPeer::CODPROMOZIONE),
- Criteria::LEFT_JOIN))
- ->withColumn('Promozioni.Priorita', 'Priorita')
- ->withColumn('Promozioni.Prossimoordine', 'Prossimoordine')
- ->orderBy('Priorita')
- ->orderByDataregistrazione()
- ->orderByOraregistrazione()
- ->find($con);
- foreach ($coupons as $coupon) {
- $coupon = $this->__toCredit($coupon);
- $promoraw = PromozioniQuery::create()
- ->filterByCodportale($coupon->getCodportale())
- ->filterByCodpromozione($coupon->getCodpromozione())
- ->where('Promozioni.Datascadenza >= ?', new DateTime())
- ->findOne($con);
- $visible = (empty($promoraw) || (!empty($promoraw) &&
- (($visibile == 1 && $promoraw->getVisibile() == 0) ||
- ($visibile == 0 && $promoraw->getVisibile() == 1))
- )) ? false : true;
- /*$isApplicabileClient = false;
- if( !empty($promoraw) ){
- $isApplicabileClient = $promoraw->getCheckclients() == 0;
- if( $promoraw->getCheckclients() == 1 ){
- $promozioneClients = PromozioniclientsQuery::create()
- ->filterByCodportale( $promoraw->getCodportale())
- ->filterByCodpromozione( $promoraw->getCodpromozione())
- ->find($con);
- foreach($promozioneClients as $promozioneClient){
- if( $promozioneClient->getSoftware() == 'FOTOTAXIOLD'){
- $isApplicabileClient = true;
- break;
- }
- }
- }
- }
- if( !empty($promoraw) ){
- if($utente->getTipo() == 'F' && $promoraw->getTipofotografo()!='all'){
- $fotografo = FotografiQuery::create()
- ->filterByCodportale( $utente->getCodportale())
- ->filterByCodlaboratorio( $utente->getCodlaboratorio())
- ->filterByCodfotografo( $utente->getCodfotografo())
- ->findOne($con);
- if( !empty($fotografo) && $promoraw->getTipofotografo()!=$fotografo->getTipofotografo()){
- $isApplicabileFotografo = false;
- }
- }
- }*/
- /**************************************************************************
- * ESISTE LA PROMOZIONE ATTIVA SUL CREDIT ED E' APPLICABILE
- **************************************************************************/
- if (!(empty($promoraw)) &&
- !($promoraw->getPrimoordine() == 1 && $utente->getHaveordini() != 0) &&
- $visible &&
- $promoraw->isApplicabileUtente($utente) &&
- $promoraw->getCheckTemi() == 0 &&
- $promoraw->isApplicabileClient('FOTOTAXIOLD') &&
- $promoraw->isApplicabileFotografo($utente)
- ) {
- $promozione = new __PromozioniBean();
- $promozione->fromArray($promoraw->toArray());
- //--------------------------------------------------------------------------------------------
- // SOLO PER PROMOZIONE SME : I CREDIT CON PROMOZIONE QUANTITA' OMAGGIO CON
- // QTA USATE > QTA OMAGGIO IN PROMOZIONE VENGONO RESI INUTILIZZABILI
- //--------------------------------------------------------------------------------------------
- if ($promozione->getFlagtipopromozione() == 0 && $promozione->getQta() > 0 && $coupon->getQtausate() >= $promozione->getQta()) {
- $coupon->setUtilizzabile(0);
- $coupon->setQtausate($promozione->getQta());
- $coupon->save($con);
- } elseif ($promozione->getFlagtipopromozione() == 2 && $promozione->getValore() > 0 && $coupon->getValoreusato() > $promozione->getValore()) {
- $coupon->setUtilizzabile(0);
- $coupon->setValoreusato($promozione->getValore());
- $coupon->save($con);
- }
- //--------------------------------------------------------------------------------------
- // PER TUTTI GLI ALTRI CASI
- //--------------------------------------------------------------------------------------
- else {
- //--------------------------------------------------------------
- // PROMOZIONE QUANTITA OMAGGIO => CALCOLO QTA RESIDUE
- //--------------------------------------------------------------
- if (($promozione->getFlagtipopromozione() == 0 && $promozione->getPercsconto() == 0) || $promozione->getFlagtipopromozione() == 6) {
- if ($promozione->getAscalare() == 1 && $coupon->getQtausate() != 0) {
- $promozione->setQtaResidue($promozione->getQta() - $coupon->getQtausate());
- } else {
- $promozione->setQtaResidue($promozione->getQta());
- }
- }
- //--------------------------------------------------------------
- // PROMOZIONE A VALORE => CALCOLO VALORE RESIDUO
- //--------------------------------------------------------------
- if ($promozione->getFlagtipopromozione() == 2 || $promozione->getFlagtipopromozione() == 5 || $promozione->getFlagtipopromozione() == 6) {
- if ($promozione->getAscalare() == 1 && $coupon->getValoreusato() != 0) {
- $promozione->setValoreResiduo($promozione->getValore() - $coupon->getValoreusato());
- } else {
- $promozione->setValoreResiduo($promozione->getValore());
- }
- }
- if ($promozione->getProssimoordine() == 1 && $coupon->getProssimoordine() == 0) {
- $promozione->setDescrizione($promozione->getDescrizionealt());
- $promozione->setProssimoordine($coupon->getProssimoordine());
- $promozione->setQtaResidue($promozione->getQtaResidue() * $coupon->getMoltiplicatore());
- $promozione->setValoreResiduo($promozione->getValoreResiduo() * $coupon->getMoltiplicatore());
- $promozione->setQtaapplicasconto($promozione->getQtaapplicasconto() * $coupon->getMoltiplicatore());
- $promozione->setCondclassearticoli("");
- $promozione->setCondlistaarticoli("");
- $promozione->setQtaminimaordine(0);
- $promozione->setImpminimoordine(0);
- }
- //--------------------------------------------------------------
- // AGGIUNGO IL COUPON ALLA LISTA DEI CREDITS
- //--------------------------------------------------------------
- if (!array_key_exists($promozione->getCodpromozione(), $creditList)) {
- $creditList[$promozione->getCodpromozione()] = $promozione;
- } else {
- $giainserita = $creditList[$promozione->getCodpromozione()];
- if (($giainserita->getFlagtipopromozione() == 0 && $giainserita->getPercsconto() == 0) || $promozione->getFlagtipopromozione() == 6) {
- $giainserita->setQtaResidue($promozione->getQtaResidue() + $giainserita->getQtaResidue());
- }
- if ($promozione->getFlagtipopromozione() == 2 || $promozione->getFlagtipopromozione() == 5 || $promozione->getFlagtipopromozione() == 6) {
- $giainserita->setValoreResiduo($promozione->getValoreResiduo() + $giainserita->getValoreResiduo());
- }
- }
- } // Fine tutti altri casi
- } // fine promozione attiva ed applicabile
- } // fine iterazione coupon
- return array_values($creditList);
- }
- /**
- * Utilità per poter lavorare in editor con oggetti tipizzati
- * @param mixed $coupon
- * @return Credits
- */
- private function __toCredit($coupon)
- {
- $a = $coupon;
- return $coupon;
- }
- /**
- * Utilità per poter lavorare in editor con oggetti tipizzati
- * @param mixed $promo
- * @return __PromozioniBean
- */
- private function __toPromo($promo)
- {
- $a = $promo;
- return $a;
- }
- /**
- * Utilità per poter lavorare in editor con oggetti tipizzati
- * @param $service
- * @return
- */
- private function __toService($service)
- {
- $a = $service;
- return $a;
- }
- private function __jsonToString($listaArticoli)
- {
- return !empty($listaArticoli) ? implode("|", json_decode($listaArticoli)) : "";
- }
- //------------------------------------------------------------------------------------------------------------------
- // Luca Chiavelli
- //------------------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param string $codPortale
- * @param string $username
- * @param string $password
- * @return GetUtenteResponse
- */
- public function getUtente($codPortale, $username, $password)
- {
- $ut = new GetUtenteResponse();
- $loginStatus = $this->login($codPortale, $username, $password, false);
- //login fallito
- if ($loginStatus != self::LOGIN_STATUS_OK) {
- $ut->setStatusMessage(GetUtenteResponse::STATUS_USER_NOT_FOUND, array($codPortale, $username, $password));
- return $ut;
- }
- try {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $utente = UtentiQuery::create()->filterByCodportale($codPortale)
- ->filterByUsername($username)
- ->findOne($con);
- if (empty($utente)) {
- $utente = UtentiQuery::create()->filterByCodportaleold($codPortale)
- ->filterByUsername($username)
- ->findOne($con);
- }
- $ut->setCodPortale($utente->getCodportale());
- $ut->setCodLaboratorio($utente->getCodlaboratorio());
- $ut->setCodFotografo($utente->getCodfotografo());
- $ut->setUsername($utente->getUsername());
- $ut->setPassword($utente->getPassword());
- $ut->setProvenienza($utente->getProvenienza());
- $ut->setTipo($utente->getTipo());
- $ut->setRuolo($utente->getFkruolo());//
- $ut->setFkCategoriaUtente($utente->getFkcategoriautente());
- $ut->setClassificazione($utente->getClassificazione());
- $ut->setFkTipoPagamento($utente->getFktipopagamento());
- $ut->setConsegna($utente->getConsegna());
- $ut->setLegatoFotografo($utente->getLegatofotografo());
- $ut->setRagioneSociale($utente->getRagionesociale());
- $ut->setIndirizzo($utente->getIndirizzo());
- $ut->setCap($utente->getCap());
- $ut->setCitta($utente->getCitta());
- $ut->setProvincia($utente->getProvincia());
- $ut->setNazione($utente->getNazione());
- $ut->setTel($utente->getTel());
- $ut->setFax($utente->getFax());
- $ut->setMail($utente->getMail());
- $ut->setCodCard($utente->getCodcard());
- $ut->setPassCard($utente->getPasscard());
- $ut->setAbilitato($utente->getAbilitato());
- $ut->setMaxFido($utente->getMaxfido());
- $ut->setTempoFido($utente->getTempofido());
- $ut->setMaxOrdineAutomatico($utente->getMaxordineautomatico());
- $ut->setAttivato($utente->getAttivato());
- $ut->setPiva($utente->getPiva());
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
- $ut->setStatusMessage(GetUtenteResponse::STATUS_SERVER_ERROR, $e->getMessage());
- }
- return $ut;
- }
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param string $codPortale
- * @param string $username
- * @param string $password
- * @param string $numOrdine
- * @return array
- */
- public function getOrdine($codPortale, $username, $password, $numOrdine)
- {
- $ut = new GetUtenteResponse();
- $loginStatus = $this->login($codPortale, $username, $password, false);
- //login fallito
- if ($loginStatus != self::LOGIN_STATUS_OK) {
- $ut->setStatusMessage(GetUtenteResponse::STATUS_USER_NOT_FOUND, array($codPortale, $username, $password));
- return $ut;
- }
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- try {
- $utente = UtentiQuery::create()->filterByCodportale($codPortale)
- ->filterByUsername($username)
- ->findOne($con);
- if (empty($utente)) {
- $utente = UtentiQuery::create()->filterByCodportaleold($codPortale)
- ->filterByUsername($username)
- ->findOne($con);
- }
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
- $ut->setStatusMessage(GetUtenteResponse::STATUS_SERVER_ERROR, $e->getMessage());
- }
- $codLaboratorio = $utente->getCodlaboratorio();
- if($utente->getConsegna()==="D"){
- $fotografoPostale = FotografipostaliQuery::create()->filterByAttivo(true)->findOne($con);
- $codLaboratorio = $fotografoPostale->getCodlaboratorio();
- }
- //trova ordine utente
- $ord = OrdinitestataQuery::create()->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByNumordine($numOrdine)
- ->findOne($con);
- //restituisci ordine anche se vuoto;
- return $ordine = array(
- "codLaboratorio" => $ord->getCodlaboratorio(),
- "codFotografo" => $ord->getCodfotografo(),
- "numOrdine" => $ord->getNumOrdine(),
- "username" => $ord->getUsername(),
- "consegna" => $ord->getConsegna(),
- "stato" => $ord->getStato(),
- "autorizzazioneFotografo" => $ord->getAutorizzazionefotografo(),
- "fkTipoPagamento" => $ord->getFkTipoPagamento(),
- "packaging" => $ord->getPackaging(),
- "ragioneSociale" => $ord->getRagioneSociale(),
- "indirizzo" => $ord->getIndirizzo(),
- "cap" => $ord->getCap(),
- "citta" => $ord->getCitta(),
- "provincia" => $ord->getProvincia(),
- "nazione" => $ord->getNazione(),
- "mail" => $ord->getMail(),
- "urlServerFtp" => $ord->getUrlServerFtp(),
- "urlDirFtp" => $ord->getUrlDirFtp(),
- "urlTracking" => $ord->getUrlTracking(),
- "nota" => $ord->getNota(),
- "dataRicezioneOrdine" => $ord->getDataRicezioneOrdine(),
- "dataAutorizzazioneOrdine" => $ord->getDataAutorizzazioneOrdine(),
- "dataInvioLaboratorio" => $ord->getDatainviolaboratorio(),
- "dataRicezioneLaboratorio" => $ord->getDataricezionelaboratorio(),
- "dataStampaOrdine" => $ord->getDatastampaordine(),
- "dataSpedizione" => $ord->getDataspedizione(),
- "dataRicezioneFotografo" => $ord->getDataricezionefotografo(),
- "valoreOrdine" => $ord->getValoreordine(),
- "rifCliente" => $ord->getRifcliente(),
- "rifBancaSella" => $ord->getRifbancasella(),
- "percSconto" => $ord->getPercsconto(),
- "impSconto" => $ord->getImpsconto(),
- "desTipoSpedizione" => $ord->getDestipospedizione(),
- "speseSpedizione" => $ord->getSpesespedizione(),
- );
- }
- //------------------------------------------------------------------------------------------------------------------
- // IMPLEMENTATO X GESTIONE BROWSER NON MODALE
- //------------------------------------------------
- /**
- * @param string $codPortale
- * @param string $codLaboratorio
- * @param string $codFotografo
- * @param string $numOrdine
- * @return int
- */
- public function getOrderStatus($codPortale, $codLaboratorio, $codFotografo, $numOrdine)
- {
- $status = 999;
- $unicredit = new Batch_PagamentiUnicredit();
- $unicredit->verificaPagamentiUnicredit("LAST_HOUR");
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $ord = OrdinitestataQuery::create()->filterByCodlaboratorio($codLaboratorio)
- ->filterByCodportale($codPortale)
- ->filterByCodfotografo($codFotografo)
- ->filterByNumordine($numOrdine)
- ->findOne($con);
- //cascata per cercare di trovare lo stato di un ordine domicilio
- if(empty($ord))
- {
- $fotografoPostale = FotografipostaliQuery::create()->filterByAttivo(true)->findOne($con);
- $ord = OrdinitestataQuery::create()->filterByCodlaboratorio($fotografoPostale->getCodlaboratorio())
- ->filterByCodportale($codPortale)
- ->filterByNumordine($numOrdine)
- ->findOne($con);
- }
- if(empty($ord))
- {
- $ord = OrdinitestataQuery::create()->filterByCodportale($codPortale)
- ->filterByNumordine($numOrdine)
- ->filterByConsegna("D")
- ->orderByDataricezioneordine("desc")
- ->findOne($con);
- }
- if ($ord != null) {
- $status = $ord->getStato();
- }
- return intval($status);
- }
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param array $articolo
- * @param struct $utente
- * @param array $fotografo
- * @return array
- */
- private static function getListino($articolo, $utente, $fotografo)
- {
- $listino = null;
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $listinoFotografo = ListiniQuery::create()->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getCodlaboratorio())
- ->filterByCodlistino($fotografo->getCodpersonalizzato())
- ->filterByCodarticolo($articolo->getCodarticolo())
- ->findOne($con);
- if ($utente->getLegatoFotografo() == 1 && !empty($listinoFotografo)) {
- $listino = $listinoFotografo;
- }
- $listinoLaboratorio = ListiniQuery::create()->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getcodLaboratorio())
- ->filterByCodlistino('0')
- ->filterByCodarticolo($articolo->getCodarticolo())
- ->findOne($con);
- if (empty($listino) && !empty($listinoLaboratorio)) {
- $listino = $listinoLaboratorio;
- }
- $listinoPortale = ListiniQuery::create()->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio('0')
- ->filterByCodlistino('0')
- ->filterByCodarticolo($articolo->getCodarticolo())
- ->findOne($con);
- if (empty($listino) && !empty($listinoPortale)) {
- $listino = $listinoPortale;
- }
- return $listino;
- }
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param array $e
- * @return string
- */
- public function getResponseException($e)
- {
- $message = '<?xml version="1.0" encoding="ISO-8859-1"?><methodResponse><fault><value><struct><member><name>faultString</name><value>org.apache.xmlrpc.XmlRpcException: ';
- $message .= $e->getMessage() . " " . $e->getTraceAsString();
- $message .= '</value></member><member><name>faultCode</name><value><int>';
- $message .= $e->getCode();
- $message .= '</int></value></member></struct></value></fault></methodResponse>';
- return $message;
- }
- //------------------------------------------------------------------------------------------------------------------
- // PYTAXY LOGGER
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param string $msgerr
- */
- public function printClientErr($msgerr)
- {
- $this->logger->log(__FILE__, __LINE__, "LOG PYTAXI ERROR: " . $msgerr, Zend_Log::ERR);
- }
- //------------------------------------------------------------------------------------------------------------------
- /**
- * map=(codPortale, username, password)
- *
- * @param struct $map
- * @param string $tipoServizio
- * @return array
- */
- public function getArticoli($map, $tipoServizio)
- {
- try {
- $ut = new GetUtenteResponse();
- $loginStatus = $this->login($map["codPortale"], $map["username"], $map["password"], false);
- //login fallito
- if ($loginStatus != self::LOGIN_STATUS_OK) {
- $ut->setStatusMessage(GetUtenteResponse::STATUS_USER_NOT_FOUND, array($map["codPortale"], $map["username"], $map["password"]));
- return $ut;
- }
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- try {
- $utente = UtentiQuery::create()->filterByCodportale($map["codPortale"])
- ->filterByUsername($map["username"])
- ->findOne($con);
- if (empty($utente)) {
- $utente = UtentiQuery::create()->filterByCodportaleold($map["codPortale"])
- ->filterByUsername($map["username"])
- ->findOne($con);
- }
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
- $ut->setStatusMessage(GetUtenteResponse::STATUS_SERVER_ERROR, $e->getMessage());
- }
- $codPortale = $utente != null ? $utente->getCodPortale() : $map["codPortale"];
- //------------------------------------------
- $portale = PortaliQuery::create()->filterByCodportale($codPortale)
- ->findOne($con);
- if ($portale == null) {
- throw new Exception("Portale non Esistente per portale: " . $codPortale);
- }
- if ($portale->getTipoPortale() == "D" || $utente->getCodFotografo() == 0) {
- $fotografo = FotografiQuery::create()->filterByCodportale($utente->getCodPortale())
- ->filterByAbilitato('1')
- ->findOne($con);
- } else {
- $fotografo = FotografiQuery::create()->filterByCodportale($utente->getCodPortale())
- ->filterByCodlaboratorio($utente->getCodLaboratorio())
- ->filterByCodfotografo($utente->getCodFotografo())
- ->findOne($con);
- }
- if ($fotografo == null) {
- throw new Exception("Fotografo non Esistente per portale: " . $portale->getCodPortale() . " username: " . $utente->getUsername());
- }
- $codLaboratorio = $utente->getCodlaboratorio();
- $articoliList = ArticoliQuery::create()->filterByCodportale($portale->getCodPortale())
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByFlagtipoutente(array($utente->getTipo(), 'B'))
- ->filterByFktiposervizio($tipoServizio)
- ->filterByVisualizzabile(array(1, 2, 3))
- /*->condition('cond1', 'Articoli.flagTipoUtente = ?', $utente->getTipo())
- ->condition('cond2', 'Articoli.flagTipoUtente = ?', 'B')
- ->combine(array('cond1', 'cond2'), 'or', 'cond12')
- ->condition('cond5', 'visualizzabile = ?', '1')
- ->condition('cond6', 'visualizzabile = ?', '2')
- ->condition('cond7', 'visualizzabile = ?', '3')
- ->combine(array('cond5', 'cond6', 'cond7'), 'or', 'cond567')
- ->condition('cond3', 'fkTipoServizio = ?', $tipoServizio)
- ->where(array('cond12', 'cond3', 'cond567'), 'and')*/
- ->find($con);
- if ($articoliList == null || empty($articoliList)) {
- $articoliList = ArticoliQuery::create()->filterByCodportale($portale->getCodPortale())
- ->filterByFlagtipoutente(array($utente->getTipo(), 'B'))
- ->filterByFktiposervizio($tipoServizio)
- ->filterByVisualizzabile(array(1, 2, 3))
- ->find($con);
- }
- if ($articoliList == null) {
- throw new Exception("Articoli non Presenti per portale: " . $codPortale . " username: " . $map["username"] . " password: " . $map["password"]);
- }
- $listiniFotografo = ListiniQuery::create()->filterByCodportale($utente->getCodPortale())
- ->filterByCodlaboratorio($utente->getCodLaboratorio())
- ->filterByCodlistino($fotografo->getCodpersonalizzato())
- ->filterByCodpersonalizzato('0')
- ->find($con);
- $listiniLaboratorio = ListiniQuery::create()->filterByCodportale($utente->getCodPortale())
- ->filterByCodlaboratorio($utente->getCodLaboratorio())
- ->filterByCodlistino('0')
- ->filterByCodpersonalizzato('0')
- ->find($con);
- $listiniPortale = ListiniQuery::create()->filterByCodportale($utente->getCodPortale())
- ->filterByCodlaboratorio('0')
- ->filterByCodlistino('0')
- ->filterByCodpersonalizzato('0')
- ->find($con);
- $articoliMap = array();
- foreach ($articoliList as $articolo) {
- $articolo->setArticoloTransfert($fotografo, $utente->getLegatofotografo(), $utente->getTipo());
- $listino = null;
- //listino personalizzato fotografo
- //if ($utente->getLegatofotografo() == 1 && ($listiniFotografo != null || !empty($listiniFotografo))) {
- $applicaListinoFotografo = $utente->getCodportale() == "rikorda" ? ($utente->getFkruolo() == Account_Service::SHOP_ROLE) : ($utente->getLegatofotografo() == 1);
- if ( $applicaListinoFotografo && ($listiniFotografo != null || !empty($listiniFotografo))) {
- foreach ($listiniFotografo as $lF) {
- if ($lF->getCodArticolo() == $articolo->getCodArticolo()) {
- $listino = $lF;
- break;
- }
- }
- }
- //listino laboratorio
- if ($listino == null && ($listiniLaboratorio != null || !empty($listiniLaboratorio))) {
- foreach ($listiniLaboratorio as $lL) {
- if ($lL->getCodArticolo() == $articolo->getCodArticolo()) {
- $listino = $lL;
- break;
- }
- }
- }
- //listino portale
- if ($listino == null && ($listiniPortale != null || !empty($listiniPortale))) {
- foreach ($listiniPortale as $lP) {
- if ($lP->getCodArticolo() == $articolo->getCodArticolo()) {
- $listino = $lP;
- break;
- }
- }
- }
- if ($listino != null) {
- $articolo->setListino($listino);
- $articoliMap[$articolo->getCodArticolo()] = $articolo->getArticoloAsMap();//vorrebbe una mappa
- } else {
- throw new Exception("Listino non presente per portale: " . $utente->getCodportale() . " username: " . $utente->getUsername() . " password: " . $utente->getPassword() . " articolo: " . $articolo->getCodArticolo());
- }
- }
- return $articoliMap;
- } catch (Exception $e) {
- $e->getTrace();
- throw new Exception($e->getMessage());
- }
- }
- //----------------------------------------------------------------------
- // PER BUG ASSEMBLATORE
- //----------------------------------------------------------------------
- /**
- * @param string $codLaboratorio
- * @return array
- * @throws Exception
- */
- public function getArticoliAssemblatore($codLaboratorio)
- {
- $articoliMap = array();
- try {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- //-----------------------------------------------------
- // CONTROLLO PARAMETRI OBBLIGATORI
- //-----------------------------------------------------
- if ($codLaboratorio == null) {
- throw new Exception("Parametri obbligatori mancanti: COD.LABORATORIO" . $codLaboratorio);
- }
- $sql_where = "Articoli.codLaboratorio='" . $codLaboratorio . "' order by Portali.prioritaAssemblatore, Articoli.codArticolo";
- $articoliList = ArticoliQuery::create()->addJoinObject(new Join(array(ArticoliPeer::CODPORTALE),
- array(PortaliPeer::CODPORTALE),
- Criteria::LEFT_JOIN))
- ->where($sql_where)
- ->find($con);
- foreach ($articoliList as $articolo) {
- if ($articoliMap[$articolo->getCodArticolo()] == null) {
- $articoliMap[strtolower($articolo->getCodArticolo())] = $articolo->getArticoloAsMap();
- }
- }
- return $articoliMap;
- } catch (Exception $e) {
- $e->getTrace();
- throw new Exception($e->getMessage());
- }
- }
- //------------------------------------------------------------------------------------------------------------------
- // OFFLINE - CREAZIONE PACCHETTO/DOWNLOAD AGGIORNAMENTI
- //------------------- --------------------------------------
- /**
- * @param struct $map
- * @return struct
- * @throws Exception
- */
- public function getArticoliPacchetto($map)
- {
- try {
- //-----------------------------------------------------
- // CONTROLLO PARAMETRI OBBLIGATORI
- //-----------------------------------------------------
- if ($map["codLaboratorio"] == null || $map["tipoUtente"] == null || $map["modalita"] == null || $map["legatoFotografo"] == null) {
- throw new Exception("Parametri obbligatori mancanti: COD.LABORATORIO" . $map["codLaboratorio"] . " TIPO UTENTE:" . $map["tipoUtente"] . " MODALITA:" . $map["modalita"] . " LEGATO FOTOGRAFO:" . $map["legatoFotografo"]);
- }
- //----------------------------------------------------
- // CONVERSIONE PORTALE
- //----------------------------------------------------
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $cp = ConversioneportaliQuery::create()->filterByCodportaleold($map["codPortale"])
- ->filterByCodlaboratorioold('0')
- ->filterByCodfotografoold('0')
- ->filterByCodgruppoold('')
- ->findOne($con);
- $codPortale = $cp != null ? $cp->getCodportalenew() : (string)$map["codPortale"];
- //----
- $portale = PortaliQuery::create()->filterByCodportale($codPortale)
- ->findOne($con);
- if ($portale == null) {
- throw new Exception("Portale non Esistente: " . $codPortale);
- }
- //------------------------------------
- // PARAMETRI
- //------------------------------------
- $codLaboratorio = (string)$map["codLaboratorio"];
- $tipoUtente = (string)$map["tipoUtente"];
- $modalita = intval((string)$map["modalita"]);
- $legatoFotografo = intval((string)$map["legatoFotografo"]);
- $fotografo = null;
- if ($map["codFotografo"] != null) {
- $fotografo = FotografiQuery::create()->filterByCodportale($portale->getCodPortale())
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByCodfotografo($map["codFotografo"])
- ->findOne($con);
- if ($fotografo == null) {
- throw new Exception("Fotografo non Esistente: " . $map["codFotografo"]);
- }
- }
- //---------------------------------------------------
- // PRENDE SOLO I SERVIZI ASSOCIATI AL LABORATORIO
- //---------------------------------------------------
- //$sql1 = "left join ServiziLaboratori on ( Servizi.codPortale=ServiziLaboratori.codPortale and Servizi.codServizio=ServiziLaboratori.codServizio) where Servizi.codPortale='" . $portale->getCodportale() . "' and ServiziLaboratori.codLaboratorio='" . $codLaboratorio . "'";
- //->condition($sql1)->find($con)->toArray();
- $serviziList = ServiziQuery::create()->filterByCodportale($codPortale)
- ->addJoinObject(new Join(array(ServiziPeer::CODPORTALE, ServiziPeer::CODSERVIZIO),
- array(ServizilaboratoriPeer::CODPORTALE, ServizilaboratoriPeer::CODSERVIZIO),
- Criteria::LEFT_JOIN))
- ->withColumn('ServiziLaboratori.Codlaboratorio', 'Codlaboratorio')
- ->where("ServiziLaboratori.CodLaboratorio = $codLaboratorio")
- ->find($con);
- $servizi = "";
- $count = 1;
- //SE NON CI SONO SERVIZI ASSOCIATI AL LABORATORIO PRENDE DI DEFAULT STAMPA FOTO
- if (count($serviziList) == 0) {
- $servizi = "'SS'";
- } else {
- foreach ($serviziList as $servizio) {
- $servizi .= "'" . $servizio->getFkTipoServizio() . "'";
- $servizi .= ($count < count($serviziList) ? "," : "");
- $count++;
- }
- }
- /************************************************************************************
- * per modalita mista devono essere scaricati tutti gli articoli
- * per tutte le altre devono essere scaricati articoli con flag=0 o flag=modalita
- ***********************************************************************************/
- $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 . ")";
- if ($modalita == 1 || $modalita == 2) {
- $sql2 .= " and ( flagModalita=0 or flagModalita=" . $modalita . ")";
- }
- $this->logger->log(__FILE__, __LINE__, "QUERY GET ARTICOLI PACCHETTO " . $sql2, Zend_Log::INFO);
- $articoliList = ArticoliQuery::create()->where($sql2)->find($con);
- if ($articoliList == null) {
- throw new Exception("Articoli non Presenti per portale: " . $map["codPortale"] . " laboratorio: " . $map["codLaboratorio"] . " tipoUtente: " . $map["tipoUtente"] . " modalita: " . $map["modalita"]);
- }
- $listiniFotografo = null;
- if ($fotografo != null) {
- $listiniFotografo = ListiniQuery::create()->filterByCodportale($portale->getCodportale())
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByCodlistino($fotografo->getCodpersonalizzato())
- ->filterByCodpersonalizzato('0')
- ->find($con);
- }
- $listiniLaboratorio = ListiniQuery::create()->filterByCodportale($portale->getCodportale())
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByCodlistino('0')
- ->filterByCodpersonalizzato('0')
- ->find($con);
- $listiniPortale = ListiniQuery::create()->filterByCodportale($portale->getCodportale())
- ->filterByCodlaboratorio('0')
- ->filterByCodlistino('0')
- ->filterByCodpersonalizzato('0')
- ->find($con);
- $articoliServiziMap = array();
- foreach ($articoliList as $articolo) {
- $articolo->setArticoloTransfert($fotografo, $legatoFotografo, $tipoUtente);
- $listino = null;
- $codArt = $articolo->getCodarticolo();//test
- //listino personalizzato fotografo
- //if (($legatoFotografo == 1) && (count($listiniFotografo) > 0)) {
- if (($tipoUtente == 'F') && (count($listiniFotografo) > 0)) {
- foreach ($listiniFotografo as $lF) {
- if ($lF->getCodarticolo() == $articolo->getCodArticolo()) {
- $listino = $lF;
- break;
- }
- }
- }
- //listino laboratorio
- if (empty($listino) && (count($listiniLaboratorio) > 0)) {
- foreach ($listiniLaboratorio as $lL) {
- $codlL = $lL->getCodArticolo();//test
- if ($lL->getCodArticolo() == $articolo->getCodArticolo()) {
- $listino = $lL;
- break;
- }
- }
- }
- //listino portale
- if (empty($listino) && (count($listiniPortale) > 0)) {
- foreach ($listiniPortale as $lP) {
- $codlP = $lP->getCodArticolo();//test
- if ($lP->getCodarticolo() == $articolo->getCodarticolo()) {
- $listino = $lP;
- break;
- }
- }
- }
- if ($listino != null) {
- $articolo->setListino($listino);
- if ($articoliServiziMap[$articolo->getFkTipoServizio()] == null) {
- $articoliMap = array();
- $articoliMap[$articolo->getCodArticolo()] = $articolo->getArticoloAsMap();//si aspetta una mappa
- $articoliServiziMap[$articolo->getFkTipoServizio()] = $articoliMap;
- } else {
- $articoliMap = $articoliServiziMap[$articolo->getFkTipoServizio()];
- $articoliMap[$articolo->getCodArticolo()] = $articolo->getArticoloAsMap();
- $articoliServiziMap[$articolo->getFkTipoServizio()] = $articoliMap;
- }
- } else {
- throw new Zend_XmlRpc_Exception("Listino non presente per portale: " . $portale->getCodPortale() . " laboratorio: " . $codLaboratorio . " articolo: " . $articolo->getCodArticolo());
- }
- }
- return $articoliServiziMap;
- } catch (Exception $e) {
- $e->getTrace();
- throw new Exception($e->getMessage());
- }
- }
- //--------------------------------------------------------------------------------------
- /**
- * @param array $errorMap
- * @param string $codeError
- * @param string $message
- */
- private static function addMsgToErrorMap($errorMap, $codeError, $message)
- {
- $systemError = array();
- $messageError = array();
- if ($errorMap['0'] != null) {
- $systemError = $errorMap['0'];
- }
- if ($errorMap['1'] != null) {
- $messageError = $errorMap['1'];
- }
- if ($codeError == "0") {
- array_push($systemError, $message);
- $errorMap["0"] = $systemError;
- } else {
- array_push($messageError, $message);
- $errorMap["1"] = $messageError;
- }
- return $errorMap;
- }
- //---------------------------------------------------------------------------------------
- // FONT LIST
- //---------------------------------------------------------------------------------------
- /**
- * @param string $so
- * @return array
- */
- public function getFontList($so)
- {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $fontList = FontQuery::create()->filterBySistemaOperativo($so)
- ->find($con);
- for ($i = 0; $i < count($fontList); $i++) {
- $fontMap[$fontList[$i]->getNome()] = array(intval($fontList[$i]->getTolleranza()), $fontList[$i]->getPredefinito());
- }
- return $fontMap;
- }
- //------------------------------------------------------------------------------------------------------------------
- // FONT
- //------------------------------------------------------------------------------------------------------------------
- /* EARLTP: porting di un metodo java per fototaxi, di fatto non serve
- * NON USATO
- *
- * @param array $pathFont
- * @return array
- */
- public function getFontsFile($pathFont)
- {
- $config = Zend_Registry::get('Redarea_Configuration');
- $pathDir = $config->path->var_labo . "/SERVIZI/font";
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- for ($i = 0; $i < count($pathFont); $i++)//rows as row
- {
- $so = substr($pathFont[$i], 0, strrpos($pathFont[$i], "/"));//
- $nomeFont = substr($pathFont[$i], strrpos($pathFont[$i], "/") + 1, strlen($pathFont[$i]));//nome del file-> da ultimo / a fine path
- $path = $pathDir . "/" . $pathFont[$i];//path completo
- $fb = FontQuery::create()->filterBySistemaOperativo($so)
- ->filterByNome($nomeFont)
- ->findOne($con);
- if (file_exists($path) && $fb != null) {
- //$imgBytes = $this->getByteFromFile($path);
- $imgBytes = file($path);
- $string = implode($imgBytes);
- $resultMap[$pathFont[$i]] = base64_encode($string);
- }
- }
- return $resultMap;
- }
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param struct $map
- * @return array
- * @throws Exception
- * @throws ServiceException
- */
- public function getSpeseSpedizione($map)
- {
- $ut = new GetUtenteResponse();
- $loginStatus = $this->login($map['codPortale'], $map['username'], $map['password'], false);
- //login fallito
- if ($loginStatus != self::LOGIN_STATUS_OK) {
- $ut->setStatusMessage(GetUtenteResponse::STATUS_USER_NOT_FOUND, array($map['codPortale'], $map['username'], $map['password']));
- return $ut;
- }
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- try {
- $utente = UtentiQuery::create()->filterByCodportale($map['codPortale'])
- ->filterByUsername($map['username'])
- ->findOne($con);
- if (empty($utente)) {
- $utente = UtentiQuery::create()->filterByCodportaleold($map['username'])
- ->filterByUsername($map['username'])
- ->findOne($con);
- }
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage() . "\n" . $e->getTraceAsString(), Zend_Log::ERR);
- $ut->setStatusMessage(GetUtenteResponse::STATUS_SERVER_ERROR, $e->getMessage());
- }
- $codPortale = $utente != null ? $utente->getCodPortale() : $map['codPortale'];
- //----------------
- $portale = PortaliQuery::create()->filterByCodportale($codPortale)
- ->findOne($con);
- if ($utente == null) {
- throw new Exception("Utente non esistente per portale: " . $codPortale);
- }
- //----------------
- /*// COMMENTO JAVA //
- per messa online paypal int version = map.get("version") == null ? 0 : Integer.parseInt(map.get("version").toString());
- per messa online paypal
- if( version < 15105 && "3".equals(rs.getString("codModalita"))){
- continue;
- }*/
- try {
- $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";
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $stmt = $con->prepare($sql);
- if ($stmt->execute()) {
- $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
- $spese = array();
- $spesa = array();
- foreach ($rows as $row) {
- $spesa["codModalita"] = $row["codModalita"];
- $spesa["modalita"] = $row["desModalita"];
- $spesa["codSpedizione"] = $row["codSpedizione"];
- $spesa["spedizione"] = $row["desSpedizione"];
- $spesa["codPackaging"] = $row["codPackaging"];
- $spesa["packaging"] = $row["desPackaging"];
- $spesa["pesoDa"] = $row["pesoDa"];
- $spesa["pesoA"] = $row["pesoA"];
- $spesa["costo"] = $row["costo"];
- //Costi aggiuntivi fissi
- $spesa["costoPagamento"] = $row["costoPagamento"];
- $spesa["costoSpedizione"] = $row["costoSpedizione"];
- $spesa["costoPackaging"] = $row["costoPackaging"];
- $spesa["forzaSpedizione"] = $row["forzaSpedizione"];
- array_push($spese, $spesa);//aggiunge spesa a spese
- }
- }
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
- $this->logger->log(__FILE__, __LINE__, $e->getTraceAsString(), Zend_Log::ERR);
- throw new ServiceException($e->getMessage());
- }
- return $spese;
- }
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param string $codPortale
- * @return array
- * @throws Exception
- * @throws string
- */
- public function getSpeseSpedizionePacchetto($codPortale)
- {
- //----------------------------------------------------
- // CONVERSIONE PORTALE
- //----------------------------------------------------
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $cp = ConversioneportaliQuery::create()->filterByCodportaleold($codPortale)
- ->filterByCodlaboratorioold('0')
- ->filterByCodfotografoold('0')
- ->filterByCodgruppoold()
- ->findOne($con);
- $codPortale = $cp != null ? $cp->getCodportalenew() : $codPortale;
- //------------------
- $portale = PortaliQuery::create()->filterByCodportale($codPortale)
- ->findOne($con);
- if ($portale == null) {
- throw new Exception("Portale non Esistente per portale: " . $codPortale);
- }
- $spese = array();
- try {
- $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";
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $stmt = $con->prepare($sql);
- if ($stmt->execute()) {
- $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);//prende qualcosa ma forse i dati non ci sono
- $spesa = array();
- foreach ($rows as $row) {
- $spesa["codModalita"] = $row["codModalita"];
- $spesa["modalita"] = $row["desModalita"];
- $spesa["codSpedizione"] = $row["codSpedizione"];
- $spesa["spedizione"] = $row["desSpedizione"];
- $spesa["codPackaging"] = $row["codPackaging"];
- $spesa["packaging"] = $row["desPackaging"];
- $spesa["pesoDa"] = $row["pesoDa"];
- $spesa["pesoA"] = $row["pesoA"];
- $spesa["costo"] = $row["costo"];
- //Costi aggiuntivi fissi
- $spesa["costoPagamento"] = $row["costoPagamento"];
- $spesa["costoSpedizione"] = $row["costoSpedizione"];
- $spesa["costoPackaging"] = $row["costoPackaging"];
- $spesa["forzaSpedizione"] = $row["forzaSpedizione"];
- array_push($spese, $spesa);//aggiunge spesa a spese
- }
- }
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
- $this->logger->log(__FILE__, __LINE__, $e->getTraceAsString(), Zend_Log::ERR);
- throw new ServiceException($e->getMessage());
- }
- return $spese;
- }
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param string $idTransazione
- * @return array
- */
- public function returnOrderData($idTransazione) //EARLTP: forse non testata
- {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- //DATI TRANSAZIONE
- $transazione = TransazioniapplicazioniQuery::create()->filterById($idTransazione)->findOne($con);
- //USERNAME UTENTE PER SICUREZZA
- $username = UtentiQuery::create()->filterByCodportale($transazione->getCodportale())
- ->filterByIdutente($transazione->getFkutente())
- ->select("Username")
- ->findOne($con);
- //DATI ORDINE
- $ordine = OrdinitestataQuery::create()->filterByCodportale($transazione->getCodportale())
- ->filterByCodlaboratorio($transazione->getCodlaboratorio())
- ->filterByUsername($username)
- ->findOne($con);
- $map = null;
- if ($ordine != null) {
- $map["numOrdine"] = $ordine->getNumordine();
- $map["STATUS"] = $ordine->getStato();
- }
- return $map;
- }
- //------------------------------------------------------------------------------------------------------------------
- /* EARLTP: inutile, porting di un metodo java per fototaxi, di fatto sostituito direttamente nella funzione che la
- * invocavavisto che è una riga sola
- * @param string $filePath
- * @return array
- */
- private static function getByteFromFile($filePath)
- {
- return $imgBytes = file($filePath);
- }
- //------------------------------------------------------------------------------------------------------------------
- /*
- * return array
- */
- public function downloadFromRegistraUtente()
- {
- $idSessione = $_REQUEST["jsessionid"];
- if (!empty($idSessione)) {
- try {
- $internalTransaction = true;
- $con = Propel::getConnection(DATASOURCE_NAME);
- $con->beginTransaction();
- $transazione = TransazioniapplicazioniQuery::create()->filterBySessionid($idSessione)->findOne($con);
- $utente = UtentiQuery::create()->filterByUsername($transazione->getUsername())
- ->filterByIdutente($transazione->getFkutente())
- ->findOne($con);
- $cliser = $this->getCliser($utente->getCodportale(), $utente->getUsername(), $utente->getPassword());
- TransazioniapplicazioniQuery::create()->filterById($transazione->getId())->delete($con);
- if ($internalTransaction) {
- $con->commit();
- }
- return $cliser;
- } catch (Exception $e) {
- if ($internalTransaction) {
- $con->rollBack();
- }
- $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
- $this->logger->log(__FILE__, __LINE__, $e->getTraceAsString(), Zend_Log::ERR);
- throw new ServiceException($e->getMessage());
- }
- }
- }
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param struct $mapParam
- * @return struct
- * @throws Exception
- */
- public function getCliserPacchetto($mapParam)
- {
- $codPortale = $mapParam["codPortale"];
- $codLaboratorio = $mapParam["codLaboratorio"];
- $codFotografo = $mapParam["codFotografo"];
- $tipoUtente = $mapParam["tipoUtente"];
- $legatoFotografo = intval($mapParam["legatoFotografo"]);
- if ($mapParam["codPortale"] == null || $mapParam["codLaboratorio"] == null || $mapParam["tipoUtente"] == null || $mapParam["legatoFotografo"] == null) {
- 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"]);
- //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"]);
- }
- $codGruppo = $mapParam["codGruppo"] == null ? "" : $mapParam["codGruppo"];
- //----------------------------------------------------
- // CONVERSIONE PORTALE
- //----------------------------------------------------
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $cp = ConversioneportaliQuery::create()->filterByCodportaleold($codPortale)
- ->filterByCodlaboratorioold('0')
- ->filterByCodfotografoold('0')
- ->filterByCodgruppoold('')
- ->findOne($con);
- $codPortale = $cp != null ? $cp->getCodportalenew() : $codPortale;
- //----------------------------------------------------
- $laboratorio = LaboratoriQuery::create()->filterByCodportale($codPortale)
- ->filterByCodlaboratorio($codLaboratorio)
- ->findOne($con);
- $portale = PortaliQuery::create()->filterByCodportale($codPortale)
- ->findOne($con);
- if ($portale == null) {
- throw new Exception("Portale non esistente: " . $codPortale);
- }
- if ($codFotografo != "") {
- $fotografo = FotografiQuery::create()->filterByCodportale($codPortale)
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByCodfotografo($codFotografo)
- ->findOne($con);
- $utenteFotografo = UtentiQuery::create()->filterByCodportale($codPortale)
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByCodfotografo($codFotografo)
- ->filterByFkruolo('3')
- ->findOne($con);
- if ($fotografo == null) {
- $ret = new GetUtenteFotografoResponse();
- return $ret->setStatusMessage(GetUtenteFotografoResponse::STATUS_FOTOGRAFO_NOT_FOUND, array($codPortale, $codLaboratorio, $codLaboratorio));
- }
- }
- //map.put("path_tema", "theme");
- //map.put("tel", "" + utente.getTel());
- //map.put("citta", "" + utente.getCitta());
- //map.put("indirizzo", "" + utente.getIndirizzo());
- //map.put("provincia", "" + utente.getProvincia());
- //map.put("ragione_sociale", "" + utente.getRagioneSociale());
- //map.put("nazione", "" + utente.getNazione());
- //map.put("mail", "" + utente.getMail());
- //map.put("fax", "" + utente.getFax());
- //map.put("piva", "" + utente.getPiva());
- //map.put("cap", "" + utente.getCap());
- $map = new GetCliserPacchettoResponse();
- if ($legatoFotografo == 0) {
- $sitoWeb = $portale->getSitoweb();
- $mailTo = $portale->getMail();
- if ($codGruppo != "") {
- $gruppo = DominigruppiQuery::create()->filterByCodportale($codPortale)
- ->filterByCodgruppo($codGruppo)
- ->findOne($con);
- $sitoWeb = !empty($gruppo) && $gruppo->getDominio() != null && $gruppo->getDominio() != "" ? $gruppo->getDominio() : $sitoWeb;
- }
- $map->setSitoWeb($sitoWeb);
- $map->setMailTo($mailTo);
- } else {
- $map->setSitoWeb($fotografo->getSitoweb());
- $map->setMailTo($fotografo->getMail());
- }
- $map->setCodFotografo($codFotografo);
- $map->setCodLabo($codLaboratorio);
- $map->setUsername("");
- $map->setPassword("");
- $map->setTipo($tipoUtente);
- //ricordarsi dei portali di tipo misto per la consegna
- $consegna = ($tipoUtente == "U" ? $portale->getTipoportale() : "F");
- $map->setConsegna($consegna);
- $map->setTipoPortale($portale->getTipoportale());
- $map->setArtInProp($laboratorio->getArtinpropclient());
- //$map->setMaxOrdine("0");
- //$map->setFidoResiduo("0");
- //$map->setPrimoOrdine(($utente->isPrimoOrdine() ? "1" : "0"));
- $map->setPercScontoPrimoOrdine($portale->getPercscontoprimoordine());
- $map->setImpMinOrdine($portale->getImpminimoordine());
- $map->setQtaMinOrdine($portale->getQtminimaordine());
- //$map->setRagioneSociale("");
- $map->setTimeNextDownload("0");
- $map->setTimeNextDownloadNew($portale->getAggclient());
- if ($laboratorio->getClientcompressionemin() == 0 || $laboratorio->getClientcompressionemax() == 0) {
- $map->setMinQualitySpeed($portale->getClientcompressionemin());
- $map->setMaxQualitySpeed($portale->getClientcompressionemax());
- } else {
- $map->setMinQualitySpeed($laboratorio->getClientcompressionemin());
- $map->setMaxQualitySpeed($laboratorio->getClientcompressionemax());
- }
- $map->setControlloFidoFotografo($portale->getFotografosoggettofido());
- if ($fotografo != null && $utenteFotografo != null) {
- $map->setRifiutoAuto($fotografo->getFlageliminaordini());
- $mappaUtenteFotografo = array(
- "ragioneSociale" => $utenteFotografo->getRagionesociale(),
- "indirizzo" => $utenteFotografo->getIndirizzo(),
- "cap" => $utenteFotografo->getCap(),
- "citta" => $utenteFotografo->getCitta(),
- "provincia" => $utenteFotografo->getProvincia(),
- "nazione" => $utenteFotografo->getNazione(),
- );
- $map->setMappaFotografo($mappaUtenteFotografo);
- }
- //$map["prom_"+ ordine++, mapPromozioni);
- $map->setCodPortale($portale->getCodportale());
- //------------------------
- $map->setModalBrowser($portale->getModalbrowser());
- //------------------------
- $map->setPathUploadPhp("/services/upload_fototaxi.php");
- $map->setUrlServerPhp("/services/xmlrpc.php");
- return $map;
- }
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param struct $mapParam
- * @return array
- */
- public function getCliserPacchetto2($mapParam)
- {
- $ht = new GetCliserPacchettoResponse();
- $ht = $this->getCliserPacchetto($mapParam);
- $ht->setStatusMessage("0");
- $ht->setMessage("");
- return $ht;
- }
- //------------------------------------------------------------------------------------------------------------------
- // XML LAYOUT
- //---------------------------------------------------------------------------------------------------
- /**
- * @param string $codPortale
- * @param string $codAlbero
- * @return string
- */
- public function getXmlLayout($codPortale, $codAlbero)
- {
- $xml = "";
- //-------------------------------
- // CONVERSIONE PORTALE
- //-------------------------------
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $cp = ConversioneportaliQuery::create()->filterByCodportaleold($codPortale)
- ->filterByCodlaboratorioold('0')
- ->filterByCodfotografoold('0')
- ->filterByCodgruppoold('')
- ->findOne($con);
- $codPortale = $cp != null ? $cp->getCodportalenew() : $codPortale;
- //----------------------
- $ab = AlberoQuery::create()->filterByCodportale($codPortale)
- ->filterByCodalbero($codAlbero)
- ->findOne($con);
- if ($ab != null) {
- $lb = LayoutQuery::create()->filterByCodarticolo($ab->getCodArticolo())
- ->filterByCodsottoarticolo($ab->getCodSottoarticolo())
- ->findOne($con);
- if ($lb != null) {
- $xml = $lb->getXml() != null ? $lb->getXml() : "";
- }
- }
- return $xml;
- }
- //---------------------------------------------------------------------------------------------------
- // XML SINGOLO LAYOUT
- //---------------------------------------------------------------------------------------------------
- /**
- * @param string $codArticolo
- * @param string $codSottoarticolo
- * @return string
- */
- public function getXmlArticleLayout($codArticolo, $codSottoarticolo){
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $xml = "";
- $lb = LayoutQuery::create()->filterByCodarticolo($codArticolo)
- ->filterByCodsottoarticolo($codSottoarticolo)
- ->findOne($con);
- if ($lb != null) {
- $xml = $lb->getXml() != null ? $lb->getXml() : "";
- }
- return $xml;
- }
- //------------------------------------------------------------------------------------------------------------------
- // XML MODELLI
- //---------------------------------------------------------------------------------------------------
- /**
- * @param array $classi
- * @return string
- */
- public function getXmlModelli($classi)
- {
- //-- GESTIONE CACHE
- $time_start = microtime(true);
- $config = Zend_Registry::get('Redarea_Configuration');
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
- $xml .= '<MODELLI>';
- //TUTTI I MODELLI DELLE CLASSI RICHIESTE
- $modelli = array();
- foreach ($classi as $classe) {
- //-- GESTIONE CACHE
- $pathFileCache = $config->path->var_labo . "/cache/modelli_classe_" . (string)$classe;
- if (file_exists($pathFileCache)) {
- try {
- $fileContent = file($pathFileCache);
- $xml .= (string)$fileContent[0];
- $this->logger->log(__FILE__, __LINE__, "getXmlModelli CACHE in " . ((microtime(true) - $time_start) / 1000.0) . "secs");
- } catch (Exception $e) {
- print_r($e->getTrace());
- }
- } else {
- //-- GESTIONE CACHE NON PRESENTE
- $modelli = ModelliQuery::create()->filterByClasse($classe)
- ->find($con);
- $xmlClasse = "";
- foreach ($modelli as $modello) {
- if ($modello->getXml() != null && $modello->getXml() != "") {
- $xmlClasse .= $modello->getXml();
- }
- }
- //-- GESTIONE CACHE
- try {
- $handle = fopen($pathFileCache, "w"); //apre/crea file in modalità scrittura, posiziona il puntatore all'inizio
- fwrite($handle, $xmlClasse);
- } catch (Exception $e) {
- print_r($e->getTrace());
- }
- $this->logger->log(__FILE__, __LINE__, "getXmlModelli DATABASE+CACHE in " . ((microtime(true) - $time_start) / 1000.0) . "secs");
- $xml .= $xmlClasse;
- }
- }
- $xml .= '</MODELLI>';
- $this->logger->log(__FILE__, __LINE__, "getXmlModelli processed in " . ((microtime(true) - $time_start) / 1000.0) . "secs");
- return $xml;
- }
- //------------------------------------------------------------------------------------------------------------------
- // XML ALBERO FAMIGLIE
- //---------------------------------------------------------------------------------------------------
- /**
- * @param string $codPortale
- * @param string $codLaboratorio
- * @param string $codServizio
- * @return string
- //RIDEFINITO PER LE VECCHIE VERSIONI
- * public function getXmlAlbero($codPortale, $codLaboratorio, $codServizio)
- * {
- * return $this->getXmlAlbero($codPortale, $codLaboratorio, $codServizio,"U");
- * }*/
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param string $codPortale
- * @param string $codLaboratorio
- * @param string $codServizio
- * @param string $tipoUtente
- * @return string
- //RIDEFINITO PER LE VECCHIE VERSIONI=> NUOVO PARAMETRO: TIPOUTENTE (U=UTENTE; F=FOTOGRAFO; DEFAULT=UTENTE)
- * public function getXmlAlbero($codPortale, $codLaboratorio, $codServizio, $tipoUtente)
- * {
- * return $this->getXmlAlbero($codPortale, $codLaboratorio, $codServizio, $tipoUtente , 1);
- * }*/
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param string $codPortale
- * @param string $codLaboratorio
- * @param string $codServizio
- * @param string $tipoUtente
- * @param int $modalita
- * @return string
- */
- //NUOVO PARAMETRO MODALITA ( 0=ENTRAMBE; 1=ONLINE; 2=OFFLINE; DEFAULT=ONLINE )
- public function getXmlAlbero($codPortale, $codLaboratorio, $codServizio, $tipoUtente = "U", $modalita = 1)//valori de default per quelle sopra
- {
- $time_start = microtime(true);
- $config = Zend_Registry::get('Redarea_Configuration');
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $pathFileCache = $config->path->var_labo . "/cache/albero_" . $codPortale . "_" . $codLaboratorio . "_" . $codServizio . "_" . $tipoUtente . "_" . $modalita;
- if (file_exists($pathFileCache)) {
- try {
- $fileContent = file($pathFileCache);
- $this->logger->log(__FILE__, __LINE__, "getXmlAlbero processed in " . ((microtime(true) - $time_start) / 1000.0) . "secs");
- return implode($fileContent);
- } catch (Exception $e) {
- var_dump($e->getTrace());
- }
- }
- //-------------------------------------------
- // CONVERSIONE PORTALE
- //-------------------------------------------
- $cp = ConversioneportaliQuery::create()->filterByCodportaleold($codPortale)
- ->filterByCodlaboratorioold('0')
- ->filterByCodfotografoold('0')
- ->filterByCodgruppoold('')
- ->findOne($con);
- if ($cp != null) {
- $this->logger->log(__FILE__, __LINE__, "CONVERSIONE -> Portale Vecchio: " . $codPortale . " Portale Nuovo: " . $cp->getCodportalenew());
- $codPortale = $cp->getCodportalenew();
- }
- //-----------------
- $albero = new Albero();
- //------------------------------------------------------------------------------------------
- // TORNA ALBERO SERVIZIO PER I SOLI ARTICOLI E SOTTOARTICOLI PRESENTI PER LABORATORIO
- //------------------------------------------------------------------------------------------
- $alberoMap = $albero->getAlberoServizio($codPortale, $codLaboratorio, $codServizio, $tipoUtente, $modalita);
- $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
- $xml .= '<FAMIGLIE>';
- $xml .= $albero->getXmlFamiglie($alberoMap);
- $xml .= '</FAMIGLIE>';
- try {
- $handle = fopen($pathFileCache, "w");
- fwrite($handle, $xml);
- } catch (Exception $e) {
- print_r($e->getTrace());
- }
- $this->logger->log(__FILE__, __LINE__, "getXmlAlbero processed in " . ((microtime(true) - $time_start) / 1000.0) . "secs");
- return (string)$xml;
- }
- //------------------------------------------------------------------------------------------------------------------
- // MD5 CLASSI
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param array $path
- * @param string $type
- * @param string $resolution
- * @return array
- public function getMd5Extension($path, $type, $resolution)
- * {
- * return $this->getMd5Extension($path, $type, $resolution, true);
- * }*/
- /**
- * @param array $path
- * @param string $type
- * @param string $resolution
- * @param bool $calcMd5
- * @return array
- */
- public function getMd5Extension($path, $type, $resolution, $calcMd5 = true)//potrebbe no servire quella sopra così
- {
- $config = Zend_Registry::get('Redarea_Configuration');
- $pathEstensione = $config->path->var_labo . "/SERVIZI/" . strtolower($type);
- $res = strtoupper($resolution) == "H" ? "hres" : "lres";
- $resultMap = array();
- //scorro le classi
- foreach ($path as $dirPath) {
- $pathImages = $pathEstensione . "/" . $dirPath;
- if (strtolower($type) != "font") {
- $pathImages .= "/" . $res;
- }
- if (file_exists($pathImages)) {
- $files = scandir($pathImages);
- unset($files["0"]);
- unset($files["1"]);
- foreach ($files as $file) {
- if (strpos($file, "md5") !== false) //se il nome del file contiene md5 return true(ritorna anche posizione md5)
- {
- continue;
- }
- if ($calcMd5) {
- $md5 = "";
- $nameMd5 = $pathImages . "/" . $file . ".md5";
- if (file_exists($nameMd5)) {
- $md5 = file($nameMd5);
- } else {
- $md5["0"] = md5_file($pathImages . "/" . $file);
- }
- $key = $dirPath . "/" . $file;
- $resultMap[$key] = $md5["0"];
- } else {
- $resultMap = array("/SERVIZI/" . strtolower($type) . "/" . $dirPath . "/" . $file => "");
- }
- }
- } else {
- $this->logger->log(__FILE__, __LINE__, "FILE NOT FOUND" . $pathImages);
- }
- }
- return new Zend_XmlRpc_Value_Struct($resultMap);
- }
- //---------------------------------------------------------------------------------------------------
- // MD5 font
- //---------------------------------------------------------------------------------------------------
- /**
- * @return array
- * @throws Zend_Exception
- */
- public function getMd5Fonts()
- {
- $resultMap = array();
- $config = Zend_Registry::get('Redarea_Configuration');
- $pathFont = $config->path->var_labo . "/SERVIZI/font";
- if (file_exists($pathFont)) {
- $oss = scandir($pathFont);
- unset($oss["0"]);
- unset($oss["1"]);
- foreach ($oss as $os) {
- $pathInOs = $pathFont . "/" . $os;
- if (file_exists($pathInOs)) {
- $filesFont = scandir($pathInOs);
- unset($filesFont["0"]);
- unset($filesFont["1"]);
- foreach ($filesFont as $fileFont) {
- if (strpos($fileFont, "md5") !== false) //se il nome del file contiene md5 return true(ritorna anche posizione md5)
- {
- continue;
- }
- $md5 = "";
- $md5Font = $pathInOs . "/" . $fileFont . ".md5";
- if (file_exists($md5Font)) {
- $md5 = file($md5Font);
- } else {
- $md5["0"] = md5_file($pathInOs . "/" . $fileFont);
- }
- $key = $os . "/" . $fileFont;
- $resultMap[$key] = $md5["0"];
- }
- }
- }
- } else {
- $this->logger->log(__FILE__, __LINE__, "FILE NOT FOUND" . $pathFont);
- }
- return $resultMap;
- }
- //---------------------------------------------------------------------------------------------------
- // MD5 CLASSI ALL
- //---------------------------------------------------------------------------------------------------
- /**
- * @param string $type
- * @param string $resolution
- * @return array
- */
- public function getAllMd5Extension($type, $resolution)
- {
- $config = Zend_Registry::get('Redarea_Configuration');
- $pathEstensione = $config->path->var_labo . "/SERVIZI/" . strtolower($type);
- $res = strtoupper($resolution) == "H" ? "hres" : "lres";
- $resultMap = array();
- if (file_exists($pathEstensione)) {
- $alls = scandir($pathEstensione);
- unset($alls["0"]);
- unset($alls["1"]);
- foreach ($alls as $all) {
- $classe = $pathEstensione . "/" . $all;
- if (strtolower($type) != "font") {
- $classe .= "/" . $res;
- }
- if (file_exists($classe)) {
- $files = scandir($classe);
- unset($files["0"]);
- unset($files["1"]);
- foreach ($files as $file) {
- if (strpos($file, "md5") !== false) //se il nome del file contiene md5 return true(ritorna anche posizione md5)
- {
- continue;
- }
- $md5 = "";
- $md5Path = $classe . "/" . $file . ".md5";
- if (file_exists($md5Path)) {
- $md5 = file($md5Path);
- } else {
- $md5["0"] = md5_file($classe . "/" . $file);
- }
- $key = $all . "/" . $file;
- $resultMap[$key] = $md5["0"];
- }
- }
- if (!file_exists($pathEstensione)) {
- $this->logger->log(__FILE__, __LINE__, "FILE NOT FOUND" . $pathEstensione);
- }
- }
- }
- return $resultMap;
- }
- //---------------------------------------------------------------------------------------
- // CONTROLLO ORDINE PER SALVA CON NOME
- //---------------------------------------------------------------------------------------
- /**
- * @param struct $oggetti
- * @param struct $params
- * @return array
- * @throws Exception
- */
- public function checkOrdine($oggetti, $params)
- {
- try {
- $resultMap = array();
- $oggettiMap = array();
- //errorsMap viene inizializzato con un key/value per forzare la conversione in python a dictionary
- $errorsMap = array("fakeKey" => "fakeValue");
- $config = Zend_Registry::get('Redarea_Configuration');
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- //----------------------------------------------------------------------------------------
- // CONTROLLO OGGETTI
- //----------------------------------------------------------------------------------------
- foreach (array_keys($oggetti) as $oggetto) {
- $path = (string)$oggetto;
- //GESTIONE PATH PER WINDOWS
- $pathArray = strpos($path, "\\") ? explode("\\", $path) : explode("/", $path);
- $isFont = false;
- if (strtolower($pathArray["0"]) == "font") {
- $newPath = strtolower($pathArray["0"]) . "/" . $pathArray["1"] . "/" . $pathArray["2"];
- $isFont = true;
- } else {
- $newPath = strtolower($pathArray["0"]) . "/" . $pathArray["1"] . "/lres/" . $pathArray["2"];
- }
- $pathFile = $config->path->var_labo . "/SERVIZI/" . $newPath;
- //PER I FONT NON OCCORRE CONTROLLARE L'MD5
- if ($isFont) {
- if (!file_exists($pathFile)) {
- $oggettiMap[$path] = "0";
- }
- } else {
- $md5client = (string)$oggetti[$oggetto];
- if (file_exists($pathFile)) {
- $md5 = md5_file($pathFile);
- if ($md5client != $md5) {
- $oggettiMap[$path] = $md5;
- }
- } else {
- $oggettiMap[$path] = "0";
- }
- }
- }
- $resultMap["mappa oggetti"] = $oggettiMap;
- //----------------------------------------------------------------------------------------
- // CONTROLLO ORDINE
- //----------------------------------------------------------------------------------------
- //-----------------------------------
- // PARAMETRI OBBLIGATORI
- //-----------------------------------
- if ($params["username"] == null || $params["password"] == null || $params["codPortale"] == null ||
- $params["codArticolo"] == null || $params["quantita"] == null || $params["prezzoArticolo"] == null ||
- $params["tipoPagamento"] == null || $params["totaleOrdine"] == null
- ) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Parametri obbligatori mancanti");
- $resultMap["mappa errori"] = $errorsMap;
- return $resultMap;
- }
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE:CONTROLLO PARAMETRI OBBLIGATORI OK");
- //----------------------------------------
- // LOGIN UTENTE
- //----------------------------------------
- $loginStatus = $this->login((string)$params["codPortale"], (string)$params["username"], (string)$params["password"], false);
- if ($loginStatus > 0) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Login utente fallito");
- $resultMap["mappa errori"] = $errorsMap;
- return $resultMap;
- }
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE:LOGIN UTENTE OK");
- //------------------------------------------
- // DATI
- //------------------------------------------
- $utente = UtentiQuery::create()->filterByCodportale($params["codPortale"])
- ->filterByUsername($params["username"])
- ->findOne($con);
- if ($utente == null) {
- $utente = UtentiQuery::create()->filterByCodportaleold($params["codPortale"])
- ->filterByUsername($params["username"])
- ->findOne($con);
- }
- $portale = PortaliQuery::create()->filterByCodportale($utente->getCodportale())
- ->findOne($con);
- $fotografo = FotografiQuery::create()->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getCodLaboratorio())
- ->filterByCodfotografo($utente->getCodFotografo())
- ->findOne($con);
- if ($portale == null) {
- throw new Exception("Portale non esistente: " . $params["codPortale"]);
- }
- if ($fotografo == null) {
- throw new Exception("Fotografo non esistente per portale: " . $utente->getCodportale() . " username: " . $utente->getUsername());
- }
- //------------------------------------------
- $language = $portale->getLingua() . '_' . strtoupper($portale->getLingua());
- $translator = new Zend_Translate('Ini', APPLICATION_PATH . '/languages/lang.' . $language . '.ini', $language);
- //------------------------------------------
- $totaleOrdine = $params["totaleOrdine"];
- $prezzoTransfertToCheck = 0;
- //------------------------------------------------
- // CONTROLLO ESISTENZA ARTICOLO PER LABORATORIO
- //------------------------------------------------
- $articolo = ArticoliQuery::create()->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getCodLaboratorio())
- ->filterByCodarticolo($params["codArticolo"])
- ->findOne($con);
- if ($articolo == null) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_articolo")));
- $resultMap["mappa errori"] = $errorsMap;
- return $resultMap;
- } else {
- $articolo->setArticoloTransfert($fotografo, $utente->getLegatoFotografo(), $utente->getTipo());
- if($articolo->getArticoloTransfert() != null) {
- $prezzoTransfertToCheck = $articolo->getArticoloTransfert()->getListino() !=null ? $articolo->getArticoloTransfert()->getListino()->getPrezzo1() : $prezzoTransfertToCheck;
- }
- $listino = $this->getListino($articolo, $utente, $fotografo);
- if($listino != null) {
- $articolo->setListino($listino);
- }else{
- throw new Exception("Listino non presente per portale: " . $utente->getCodPortale() . " username: " . $utente->getUsername() . " password: " . $utente->getPassword() . " articolo: " . $articolo->getCodArticolo());
- }
- }
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: ARTICOLO PRESENTE PER LABORATORIO " . $articolo->getCodArticolo());
- //-----------------------------------------
- // CONTROLLO ESISTENZA PAGINA AGGIUNTIVA
- //-----------------------------------------
- $paginaAggiuntiva = null;
- $numPagineAggiuntive = 0;
- $prezzoPaginaAggiuntiva = 0;
- if (!empty($params["codPaginaAggiuntiva"])) {
- $paginaAggiuntiva = ArticoliQuery::create()->filterByCodportale($utente->getCodPortale())
- ->filterByCodlaboratorio($utente->getCodlaboratorio())
- ->filterByCodarticolo($params["codPaginaAggiuntiva"])
- ->findOne($con);
- if ($paginaAggiuntiva == null) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_pag_agg")));
- $resultMap["mappa errori"] = $errorsMap;
- return $resultMap;
- }
- //PARAMETRO NUM PAGINE AGGIUNTIVE MANCANTE
- if ($params["numPagineAggiuntive"] == null) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Parametro numPagineAggiuntive non settato");
- $resultMap["mappa errori"] = $errorsMap;
- return $resultMap;
- }
- $numPagineAggiuntive = intval($params["numPagineAggiuntive"]);
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: PAGINA AGGIUNTIVA " . $paginaAggiuntiva->getCodarticolo());
- //---------------------------------------
- // SCAGLIONE PREZZO PAGINA AGGIUNTIVA
- //---------------------------------------
- $listinoPa = $this->getListino($paginaAggiuntiva, $utente, $fotografo);
- if(!empty($listinoPa)) {
- $prezzoPaginaAggiuntiva = $listinoPa->getPrezzo(intval($params["numPagineAggiuntive"]));
- if((Double)$params["prezzoPaginaAggiuntiva"] != $prezzoPaginaAggiuntiva) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1",sprintf($translator->_("check.ordine.msg_err_pag_agg_prezzo")));
- }
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: PREZZO PAGINA AGGIUNTIVA " . $prezzoPaginaAggiuntiva);
- $totaleOrdine += $prezzoPaginaAggiuntiva * $numPagineAggiuntive;
- } else {
- throw new Exception("Listino Pagina Aggiuntiva non presente per portale: " . $utente->getCodportale() . " username: " . $utente->getUsername() . " password: " . $utente->getPassword() . " articolo: " . $paginaAggiuntiva->getCodarticolo());
- }
- }
- //--------------------------------------------
- // SCAGLIONE PREZZO ARTICOLO
- //--------------------------------------------
- try {
- $quantita = intval($params["quantita"]);
- } catch (Exception $e) {
- $this->logger->log(__FILE__, __LINE__, $e->getTraceAsString());
- //addMsgToErrorMap(errorsMap,"1","La quantita contiene un valore non valido");
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_quantita")));
- $resultMap["mappa errori"] = $errorsMap;
- return $resultMap;
- }
- $prezzoArticolo = $articolo->getListino()->getPrezzo($quantita);
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: PREZZO ARTICOLO " . $prezzoArticolo);
- if (floatval($params["prezzoArticolo"]) != $prezzoArticolo) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_articolo_prezzo")));
- }
- //totaleOrdine += prezzoArticolo * (Integer.parseInt(params.get("quantita").toString()) );
- //--------------------------------------------
- // TRANSFERT
- //--------------------------------------------
- if (!empty($params["flagTransfert"]) && (string)$params["flagTransfert"] == "1") {
- $transfert = $articolo->getArticoloTransfert();
- if (!empty($transfert)) {
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CODICE TRANSFERT " . $transfert->getCodArticolo());
- $listinoTransfert = $this->getListino($transfert, $utente, $fotografo);
- if (!empty($listinoTransfert)) {
- $prezzoTransfert = $listinoTransfert->getPrezzo1();
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: PREZZO TRANSFERT " . $prezzoTransfert);
- //PARAMETRO PREZZO TRANSFERT MANCANTE
- if (empty($params["prezzoTransfert"])) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Parametro prezzo transfert mancante");
- $resultMap["mappa errori"] = $errorsMap;
- return $resultMap;
- }
- if ($prezzoTransfert != floatval((string)$params["prezzoTransfert"])) {
- //addMsgToErrorMap(errorsMap,"1","Alcune delle voci di costo che compongono il totale ordine sono variate");
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_totale")));
- }
- } else {
- throw new Exception("Listino Transfert non presente per portale: " . $utente->getCodPortale() . " username: " . $utente->getUsername() . " password: " . $utente->getPassword() . " articolo: " . $transfert->getCodArticolo());
- }
- } else {
- //addMsgToErrorMap(errorsMap,"1","Alcune delle voci di costo che compongono il totale ordine sono variate");
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_totale")));
- }
- }
- //$this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: TOTALE NON SCONTATO " . totaleOrdine);
- $checkTotale = true;
- //------------------------------------------------------------
- // SE IL FOTOGRAFO FORZA IL TOTALE NON FACCIO IL CONTROLLO
- //------------------------------------------------------------
- if ($params["totale_forzato"] != null && intval($params["totale_forzato"]) == 1) {
- $checkTotale = false;
- }
- if ($checkTotale) {
- $cartService = new Cart_Service();
- $projectService = new Projects_Service();
- $accountService = new Account_Service();
- $id_prefix = $config->db->id->prefix;
- try {
- $internalTransaction = true;
- $conT = Propel::getConnection(DATASOURCE_NAME);
- $conT->beginTransaction();
- $idProgetto = $projectService->inizializeProject($utente->getIdutente(), "fototaxi_xmr", $utente->getIdutente() . uniqid(), null, null, $conT, null);
- $xml = "<?xml version='1.0' encoding='iso-8859-15'?><PAGES><QT>" . $params["quantita"] . "</QT><CODE_ARTICOLO>" . $params["codArticolo"] . "</CODE_ARTICOLO>";
- if (!empty($params["codPaginaAggiuntiva"])) {
- $xml .= "<CODE_PAG_AGG>" . $params["codPaginaAggiuntiva"] . "</CODE_PAG_AGG><QT_PAG_AGG>" . $params["numPagineAggiuntive"] . "</QT_PAG_AGG>";
- }
- $xml .= "</PAGES>";
- ProgettiQuery::create()->filterByIdprogetto($idProgetto)->update(array("Xml" => $xml), $conT);
- $transactionId = $id_prefix . uniqid();
- $transazione = new Transazioniapplicazioni();
- $transazione->setId($transactionId);
- $transazione->setCodportale($utente->getCodportale());
- $transazione->setCodlaboratorio($utente->getCodlaboratorio());
- $transazione->setCodfotografo($utente->getCodfotografo());
- //$transazione->setCodgruppo();
- //$transazione->setCodagente($utente->getCodagente());
- $transazione->setUsername($utente->getUsername());
- $transazione->setFkutente($utente->getIdutente());
- $transazione->setDatainserimento(date("Y-m-d H:i:s"));
- $transazione->setFkprogetto($idProgetto);
- $transazione->setClient("FOTOTAXI-OLD");
- $transazione->save($conT);
- //LOGIN PER ATTIVARE PROMO
- $accountService->loginByUserId($transazione->getFkutente(), $portale->getSitoweb());
- $cartID = $cartService->addProject($utente->getIdutente(), $idProgetto, null, $conT, $transactionId, false);
- if ($internalTransaction) {
- $conT->commit();
- }
- } catch (Exception $e) {
- if ($internalTransaction) {
- $conT->rollBack();
- }
- $this->logger->log(__FILE__, __LINE__, $e, Zend_Log::ERR);
- }
- if (empty($cartID)) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", "CARRELLO NON CREATO");
- } else {
- //--Rut - 07/10/2015 - passaggio client al carrello
- $cart = $cartService->getCart($utente->getIdutente(), $cartID, $transactionId, 0.0, false, null, false, false, 'FOTOTAXI');
- $totaleCart = $cart["2"];
- $totSpese = 0;
- //-------------------------------------------------
- // PROMOZIONE
- //-------------------------------------------------
- $qtaOrdinate = 0;
- $qtaResidue = 0;
- $qtaPromo = 0;
- $valoreResiduo = 0;
- $totalePromo = 0;
- $scontaTransfert = false;
- $currentPromo = null;
- /******************************************************
- * GESTIONE CAMPAGNE APR 2012
- *****************************************************/
- $now = new DateTime();
- $campagne = CampagneQuery::create() ->filterByCodiceportale($utente->getCodportale())
- ->filterByDatainizio(array('max' => $now))
- ->filterByDatafine(array('min' => $now))
- ->filterByTipo(array('ALL'), Criteria::IN)
- ->find($con);
- $listiniCampagneMap = array();
- if(count($campagne) > 0 ) {
- foreach($campagne as $campagna) {
- $escluso = EsclusionefotograficampagneQuery::create()
- ->filterByCodportale($utente->getcodPortale())
- ->filterByCodlaboratorio($utente->getCodlaboratorio())
- ->filterByCodfotografo($utente->getCodfotografo())
- ->where("Esclusionefotograficampagne.Codcampagna = ?",
- $campagna->getCodicecampagna())
- ->orWhere("EsclusioneFotografiCampagne.Codcampagna = ''")
- ->findOne($con);
- if (empty($escluso) &&
- $campagna->isApplicabileUtente($utente) &&
- $campagna->getCheckTemi() == 0 &&
- $campagna->isApplicabileClient('FOTOTAXIOLD') &&
- $campagna->isApplicabileFotografo($utente)
- ) {
- $listiniCampagna = $campagna->getListinoPromozionale();
- foreach ($listiniCampagna as $listinoCampagna) {
- $listiniCampagneMap[$listinoCampagna->getCodicearticolo()] = $listinoCampagna;
- }
- }
- }
- }
- $promozioneCampagna = "";
- if (count($listiniCampagneMap) > 0) {
- //TODO EARLTP: vedere bene questo punto
- // c'e' un listino promozionale su uno degli articoli ordinati o sulla pagina aggiuntiva
- if (
- (array_key_exists($listiniCampagneMap, $articolo->getCodArticolo())) ||
- (!empty($params["applica_pag_agg"]) && !empty($paginaAggiuntiva) && array_key_exists($listiniCampagneMap, $paginaAggiuntiva->getCodArticolo()))
- ) {
- if (array_key_exists($listiniCampagneMap, $articolo->getCodArticolo())) {
- $listinoPromo = $listiniCampagneMap[$articolo->getCodArticolo()];
- $scontato = $listinoPromo->getPrezzo($quantita) * $quantita;
- $totalePromo += ($prezzoArticolo * $quantita) - $scontato;
- $promozioneCampagna = $listinoPromo->getCodicePromozione();
- }
- if (!empty($params["applica_pag_agg"]) && !empty($paginaAggiuntiva) && array_key_exists($listiniCampagneMap, $paginaAggiuntiva->getCodArticolo())) {
- $listinoPromo = $listiniCampagneMap[$paginaAggiuntiva->getCodArticolo()];
- $scontato = $listinoPromo->getPrezzo($numPagineAggiuntive) * $numPagineAggiuntive;
- $totalePromo += ($prezzoPaginaAggiuntiva * $numPagineAggiuntive) - $scontato;
- $promozioneCampagna = $promozioneCampagna == "" ? $listinoPromo->getCodicePromozione() : $promozioneCampagna;
- }
- //sul client non e' stata applicata la promozione campagna: vanno riscaricati il cliser e i listini promozionali
- if (empty($params["codPromozione"])) {
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CAMPAGNA PROMOZIONALE NON APPLICATA ");
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", "I prezzi devono essere aggiornati"); //todo: sostituire messaggio
- }
- /* commentato: da quando e' stata introdotta la priorita sulle promo non ha più senso poiche l'utente potrebbe
- avere una promo che ha priorita sulla campagna
- */
- //sul client e' stata applicata una promozione diversa da quella della campagna: vanno riscaricati il cliser e i listini promozionali
- /*else if( params.get("codPromozione") != null && !params.get("codPromozione").equals(promozioneCampagna) ){
- addMsgToErrorMap(errorsMap,"1","promozione applicata non valida"); //todo:cambiare messaggio errore e verificare se deve andare avanti con i controlli oppure no
- }*/
- }
- }
- /** FINE **/
- if (!empty($params["codPromozione"])) {
- if (empty($params["importoPromozione"])) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Importo promozione non settato");
- $resultMap["mappa errori"] = $errorsMap;
- return $resultMap;
- }
- $promozione = PromozioniQuery::create()->filterByCodportale($utente->getCodportale())->filterByCodpromozione($params["codPromozione"])->findOne($con);
- //==================================
- // PROMOZIONE INESISTENTE O SCADUTA
- //==================================
- $promozioneScaduta = false;
- if(!empty($promozione)){
- //TODO EARLTP: verifica che funziona
- $now = strtotime('now');
- $scadenza = strtotime($promozione->getDatascadenza());
- $promozioneScaduta = $now > $scadenza;
- /*Calendar now = new GregorianCalendar();
- now.set(Calendar.HOUR_OF_DAY, 0);
- now.set(Calendar.MINUTE, 0);
- now.set(Calendar.SECOND, 0);
- now.set(Calendar.MILLISECOND, 0);
- Calendar scadenza = new GregorianCalendar();
- scadenza.setTimeInMillis(promozione.getDataScadenza().getTime());
- promozioneScaduta = now.after(scadenza);*/
- }
- // verifica applicabilita condizioni: qta minima ordine o importo minimo ordine e classe articoli/lista articoli
- $isApplicabile = true;
- //TODO EARLTP: ho già il carrello
- $cartItems = $cart[1][0]["items"];
- /*List cartItems = new ArrayList();
- OrdineCarrelloBean ocb = new OrdineCarrelloBean();
- ocb.setArticolo(articolo);
- ocb.setQuantita(quantita);
- ocb.setPrezzo(prezzoArticolo);
- cartItems.add(ocb);
- if( paginaAggiuntiva != null ){
- OrdineCarrelloBean ocb2 = new OrdineCarrelloBean();
- ocb2.setArticolo(paginaAggiuntiva);
- ocb2.setQuantita(numPagineAggiuntive);
- ocb2.setPrezzo(prezzoPaginaAggiuntiva);
- cartItems.add(ocb2);
- }*/
- $credits = !empty($promozione) ? CreditsQuery::create()->filterByCodportale($utente->getCodportale())->filterByCodpromozione($promozione->getCodpromozione())->filterByUsername($utente->getUsername())->filterByUtilizzabile('1')->findOne($con) : array();
- if (!empty($promozione) && ($promozione->getQtaminimaordine() > 0 || $promozione->getImpminimoordine() > 0)) {
- $isApplicabile = $this->verificaApplicabilitaCondizioni($cartItems, $promozione, $credits, $params["applica_pag_agg"] != null);
- }
- if (empty($promozione) || $promozioneScaduta || !$isApplicabile) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_promo_no_attiva")));
- } else {
- //==================================
- // PROMOZIONE NON APPLICABILE
- //==================================
- if ($promozione->getPrimoordine() == 1 && !$utente->isPrimoOrdine()) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_promo_primo_ordine")));
- } else {
- $currentPromo = $promozione;
- //========================================
- // CREDITS NON DISPONIBILI PER PROMOZIONE
- //========================================
- if (count($credits) == 0 && empty($promozioneCampagna)) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_promo_usata")));
- } else {
- $flagApplicaCampagna = false;
- if (!empty($promozioneCampagna)) {
- $promoCampagna = PromozioniQuery::create()->filterByCodportale($utente->getCodportale())->filterByCodpromozione($promozioneCampagna)->findOne($con);
- $flagApplicaCampagna = $promoCampagna->getPriorita() < $promozione->getPriorita();
- }
- if (!$flagApplicaCampagna) {
- $promozione->generaItemsPromozione()
- if ($promozione->getFlagtipopromozione() == 0) {
- // qta omaggio
- if ($promozione->getPercsconto() == 0) {
- $result = $this->calcolaScontoQtaOmaggio($cartItems, $promozione, $credits, $params["applica_pag_agg"] != null, 0);
- $totalePromo = (Double)$result["totaleSconto"];
- $scontaTransfert = (Boolean)$result["scontaTransfert"];
- } // 3x2
- else {
- $totalePromo = $this->calcolaSconto3x2($cartItems, $promozione, $params["applica_pag_agg"] != null);
- }
- } // percentuale di sconto
- elseif ($promozione->getFlagtipopromozione() == 1) {
- $totalePromo = $this->calcolaScontoPercentuale($cartItems, $promozione, $params["applica_pag_agg"] != null);
- } // prepagata
- elseif ($promozione->getFlagtipopromozione() == 2) {
- $speseSped = (Double)$params["totaleSpeseSpedizione"];
- $tot = $totaleOrdine + $prezzoTransfert + $speseSped;
- $totalePromo = $this->calcolaScontoPrepagata($credits, $promozione, $tot);
- if ($totalePromo > 0 && $promozione->getPagatransfert() == 0) {
- $prezzoTransfert = 0;
- }
- } // a prezzo fisso
- elseif ($promozione->getFlagtipopromozione() == 4) {
- $totalePromo = $this->calcolaScontoPrezzoFisso($cartItems, $promozione, $params["applica_pag_agg"] != null);
- } // a valore
- elseif ($promozione->getFlagtipopromozione() == 5) {
- $totalePromo = $this->calcolaScontoValore($cartItems, $promozione, $credits, $params["applica_pag_agg"] != null);
- } // kit
- elseif ($promozione->getFlagtipopromozione() == 6) {
- $totalePromo = $this->calcolaScontoKit($cartItems, $promozione, $credits, $params["applica_pag_agg"] != null, 0);
- }
- }
- }
- }
- }
- if ($totaleOrdine > $promozione->getImpminimoordine()) {
- if ($promozione->getPagatransfert() == 0 && $promozione->getFlagtipopromozione() != 2 && $scontaTransfert) {
- $prezzoTransfert = 0;
- }
- } else {
- $totalePromo = 0;
- }
- $totalePromo = (float)($totalePromo + 0.005);
- $totalePromoClient = (Double)$params["importoPromozione"];
- $totalePromoClient = (float)($totalePromoClient + 0.005);
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: TOTALE PROMOZIONE SERVER " . $totalePromo);
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: TOTALE PROMOZIONE CLIENT " . $totalePromoClient);
- if ($totalePromoClient != $totalePromo) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_promo_importo")));
- }
- }
- $totaleOrdine = $totaleOrdine - $totalePromo + $prezzoTransfert;
- if (!empty($currentPromo) && $currentPromo->getFlagtipopromozione() == 2 && $totalePromo > 0) {
- $totaleOrdine = 0;
- }
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: TOTALE SCONTATO " . $totaleOrdine);
- //-------------------------------------------------------------------------
- // TIPO PAGAMENTO
- //-------------------------------------------------------------------------
- //FIDO
- if ($params["tipoPagamento"] == "0") {
- //controllo fido residuo solo se flag elimina ordini = si => Pytaxi impedisce l'invio dell'ordine se questo supera il fido
- if ($fotografo->getFlageliminaordini() == 1 && ($utente->getFkruolo() != "3" || ($utente->getFkruolo() == "3" && $portale->getFotografosoggettofido() == 1))) {
- $fidoResiduo = $accountService->getFidoResiduo($utente->getIdutente());
- if ($totaleOrdine > $fidoResiduo) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_fido")));
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CONTROLLO FIDO RESIDUO-> FIDO RESIDUO UTENTE " . $fidoResiduo);
- }
- $maxOrdineUtente = ($utente->getMaxordineautomatico() == 0) ? $fotografo->getMaxordineautomatico() : $utente->getMaxordineautomatico();
- if ($totaleOrdine > $maxOrdineUtente) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_max_ordine")));
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CONTROLLO FIDO RESIDUO-> MAX ORDINE UTENTE " . $maxOrdineUtente);
- }
- }
- } else {
- if ($params["tipoSpedizione"] == null || $params["totaleSpeseSpedizione"] == null) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "0", "Parametri tipoSpedizione e totaleSpeseSpedizione non settati");
- $resultMap["mappa errori"] = $errorsMap;
- return $resultMap;
- } else {
- $mpb = ModpagamentoQuery::create()->filterByCodportale($utente->getCodPortale())
- ->filterByCodmodalita($params["tipoPagamento"])
- ->findOne($con);
- if ($mpb == null) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_mod_pag")));
- }
- $tsb = TipospedizioneQuery::create()->filterByCodportale($utente->getCodPortale())
- ->filterByCodspedizione($params["tipoSpedizione"])
- ->findOne($con);
- if ($tsb == null) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_tipo_sped")));
- }
- if ($mpb != null && $tsb != null) {
- $peso = $articolo->getGrammi() * (intval($params["quantita"]));
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CONTROLLO SPESE SPEDIZIONE-> PESO " . $peso);
- $ssb = SpesespedizioneQuery::create()->filterByCodportale($utente->getCodPortale())
- ->filterByCodmodalita($mpb->getCodmodalita())
- ->filterByCodspedizione($tsb->getCodSpedizione())
- ->filterByCodpackaging($articolo->getCodPackaging())
- ->filterByPesoda($peso, '<=')
- ->filterByPesoa($peso, '>=')
- ->findOne($con);
- $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);
- $totSpese = $mpb->getCosto() + $ssb->getCosto();
- $totSpese = round($totSpese, 2);
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CONTROLLO SPESE SPEDIZIONE-> TOTALE SPESE " . $totSpese);
- if (intval($params["totaleSpeseSpedizione"]) < ($totSpese - 0.10) || intval($params["totaleSpeseSpedizione"]) > ($totSpese + 0.10)) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_spese_sped")));
- }
- }
- }
- }
- $totale = $totaleCart + $totSpese;
- //TODO EARLTP: il commento serve per ripristinare il funzionamento dopo la pezza
- /*if (round((float)$totaleOrdine, 2) - round((float)$totale, 2) - round((float)$prezzoTransfertToCheck, 2) < 0.01) {
- // PEZZA 2016-02-02: da sistemare!!!
- // i totali differiscono dell'importo del transfert => quindi faccio andare avanti l'ordine
- }else {*/
- //controllo totale con range di 0.10€, se fuori aggiunge errore
- if ($totale < ($totaleOrdine - 0.10) || $totale > ($totaleOrdine + 0.10)) {
- $errorsMap = $this->addMsgToErrorMap($errorsMap, "1", sprintf($translator->_("check.ordine.msg_err_tot_ordine")));
- }
- //}
- $this->logger->log(__FILE__, __LINE__, "XMLRPC METHODS->CHECK ORDINE: CONTROLLO IMPORTO ORDINE-> TOTALE ORDINE " . $totaleOrdine);
- $this->logger->log(__FILE__, __LINE__, "L'ordine ricevuto e' di " . intval($params["totaleOrdine"]));
- }
- }
- //-----------------------------------------------------------
- $resultMap["mappa errori"] = $errorsMap;
- return $resultMap;
- } catch (Exception $e) {
- echo $e->getTraceAsString();
- return null;
- }
- }
- //------------------------------------------------------------------------------------------------------------------
- //getListiniServizi: query al db e costruzione albero listini da restituire alla vista
- //------------------------------------------------------------------------------------------------------------------
- /*
- * @param string $codPortale
- * @param string $codLaboratorio
- * @param string $codServizio
- * @param string $codFotografo
- * @param string $tipoUtente
- * @param string $username
- * @param string $password
- * @return string
- */
- public function getListiniServizi($codPortale, $codLaboratorio, $codServizio, $codFotografo, $tipoUtente, $username, $password)
- {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $utente = null;
- $portale = null;
- $fotografo = null;
- $listinoFotografo = null;
- $listinoLaboratorio = null;
- $listinoPortale = null;
- if (!empty($username) && !empty($password)) {
- $utente = UtentiQuery::create()->filterByCodportale($codPortale)
- ->filterByUsername($username)
- ->findOne($con);
- if ($utente == null) {
- $utente = UtentiQuery::create()->filterByCodportaleold($codPortale)
- ->filterByUsername($username)
- ->findOne($con);
- }
- }
- //-----------------------------------
- //PARAMETRI USERNAME E PASSWORD NON PASSATI
- if ($utente == null) {
- $conversione = ConversioneportaliQuery::create()->filterByCodportaleold($codPortale)
- ->filterByCodlaboratorioold(0)
- ->filterByCodfotografoold(0)
- ->filterByCodgruppoold('')
- ->findOne($con);
- if ($conversione != null) {
- $codPortale = $conversione->getCodportalenew();
- }
- $portale = PortaliQuery::create()->filterByCodportale($codPortale)->findOne($con);
- if ($codLaboratorio != null && $codFotografo != null) {
- $fotografo = FotografiQuery::create()->filterByCodportale($codPortale)
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByCodfotografo($codFotografo)
- ->findOne($con);
- }
- } else {
- $portale = PortaliQuery::create()->filterByCodportale($utente->getCodportale())->findOne($con);
- $fotografo = FotografiQuery::create()->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getCodlaboratorio())
- ->filterByCodfotografo($utente->getCodFotografo())
- ->findOne($con);
- }
- if (!empty($portale) && !empty($codLaboratorio) && !empty($codServizio) && !empty($fotografo)) {
- //MAPPA ALBERO SERVIZIO ==> SOLO ARTICOLI E SOTTOARTICOLI PRESENTI PER LABORATORIO
- $albero = new Albero();
- $codPortale = $portale->getCodportale();
- $alberoMap = $albero->getAlberoServizio($codPortale, $codLaboratorio, $codServizio, $tipoUtente, 1);
- $listiniF = ListiniQuery::create()->filterByCodportale($codPortale)
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByCodlistino($fotografo->getCodpersonalizzato())
- ->filterByCodpersonalizzato('0')
- ->find($con);
- foreach ($listiniF as $listinoF) {
- $listiniFotografo[$listinoF->getCodarticolo()] = $listinoF;
- }
- //MAPPA LISTINI LABORATORIO E PORTALE
- $listiniL = ListiniQuery::create()->filterByCodportale($codPortale)
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByCodlistino('0')
- ->filterByCodpersonalizzato('0')
- ->find($con);
- foreach ($listiniL as $listinoL) {
- $listiniLaboratorio[$listinoL->getCodarticolo()] = $listinoL;
- }
- $listiniP = ListiniQuery::create()->filterByCodportale($codPortale)
- ->filterByCodlaboratorio('0')
- ->filterByCodlistino('0')
- ->filterByCodpersonalizzato('0')
- ->find($con);
- foreach ($listiniP as $listinoP) {
- $listiniPortale[$listinoP->getCodarticolo()] = $listinoP;
- }
- //MAPPA ARTICOLI LABORATORIO
- $articoli = ArticoliQuery::create()->filterByCodportale($codPortale)
- ->filterByCodlaboratorio($codLaboratorio)
- ->find($con);
- foreach ($articoli as $articolo) {
- $articoliMap[$articolo->getCodarticolo()] = $articolo;
- }
- /** CAMPAGNE - MARZO 2012 **/
- $campagne = CampagneQuery::create()->filterByCodiceportale($codPortale)
- ->filterByDatainizio(date("Y-m-d H:i:s"), "<=")
- ->filterByDatafine(date("Y-m-d H:i:s"), ">=")
- ->find($con);
- $listiniCampagneMap = null;
- if (sizeof($campagne) > 0) {
- foreach ($campagne as $campagna) {
- $escluso = $codFotografo != null ? EsclusionefotograficampagneQuery::create()->filterByCodportale($codPortale)
- ->filterByCodlaboratorio($codLaboratorio)
- ->filterByCodfotografo($codFotografo)
- ->where("(codCampagna='" . $campagna->getCodiceCampagna() . "' OR codCampagna='')")
- ->findOne($con)
- : null;
- if ($escluso == null) {
- $listiniCampagna = $campagna->getListinoPromozionale();
- foreach ($listiniCampagna as $listinoCampagna) {
- $listiniCampagneMap[$listinoCampagna->getCodicearticolo()] = $listinoCampagna;
- }
- }
- }
- }
- $listino = null;
- $artToTree = null;
- $legatoFotografo = ($fotografo == null) ? 0 : 1;
- foreach (array_keys($alberoMap) as $node) {
- $ab = $alberoMap[$node];
- //PER GLI ARTICOLI SETTO IL LISTINO E LE EVENTUALI PAGINE AGGIUNTIVE
- if ($ab != null && strlen($ab->getCodalbero()) == 8) {
- $art = $articoliMap[$ab->getCodarticolo()];
- if ($art != null) {
- $art->setArticolotransfert($fotografo, $legatoFotografo);
- if ($listiniFotografo != null) {
- $listino = $listiniFotografo[$ab->getCodarticolo()];
- }
- if ($listino == null) {
- $listino = $listiniLaboratorio[$ab->getCodarticolo()];
- }
- if ($listino == null) {
- $listino = $listiniPortale[$ab->getCodarticolo()];
- }
- if ($listino != null) {
- $art->setListino($listino);
- $artToTree[$art->getCodArticolo()] = $art;
- }
- if (sizeof($listiniCampagneMap) && $listiniCampagneMap[$art->getCodArticolo()] != null) {
- $listinoPromo = $listiniCampagneMap[$art->getCodArticolo()];
- $art->setListinoPromozionale($listinoPromo);
- }
- //PAGINE AGGIUNTIVE
- $listino = null;
- if ($art->getArticoloCorrelato2() != null) {
- $pa = $articoliMap[$art->getArticoloCorrelato2()];
- if ($pa != null) {
- if ($listiniFotografo != null) {
- $listino = $listiniFotografo[$pa->getCodArticolo()];
- }
- if ($listino == null) {
- $listino = $listiniLaboratorio[$pa->getCodArticolo()];
- }
- if ($listino == null) {
- $listino = $listiniPortale[$pa->getCodArticolo()];
- }
- if ($listino != null) {
- $pa->setListino($listino);
- $artToTree[$pa->getCodArticolo()] = $pa;
- }
- if (sizeof($listiniCampagneMap) > 0 && $listiniCampagneMap[$pa->getCodArticolo()] != null) {
- $listinoPromo = $listiniCampagneMap[$pa->getCodArticolo()];
- $pa->setListinoPromozionale($listinoPromo);
- }
- }
- $listino = null;
- }
- }
- }
- }
- }
- $html = $this->getHtmlFamiglie($alberoMap, $artToTree);
- return (string)$html;
- }
- //------------------------------------------------------------------------------------------------------------------
- //getHtmlFamiglie: genera tabella html per listini
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @return string
- */
- private function getHtmlFamiglie($alberi, $articoli)
- {
- $html = "<table class='pricing_list'>";
- ksort($alberi);
- foreach ($alberi as $albero) {
- $nodeCode = $albero->getCodalbero();
- if (strlen($nodeCode) == 4 && strpos($albero->getTitolo(), "***CANCELLED***") === false) {
- $html .= "<tr>";
- $html .= " <th class='famiglie' colspan=2>" . $albero->getTitolo() . "</th>";
- $html .= "</tr>";
- $html .= $this->getHtmlFigli($nodeCode, $alberi, $articoli);
- //$html .= "<tr><td style='border: none;' height=20></td></tr>";
- }
- }
- $html .= "</table>";
- return $html;
- }
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @return string
- */
- private function getHtmlFigli($node, $alberi, $articoli)
- {
- $html = "";
- ksort($alberi);
- foreach ($alberi as $albero) {
- $nodeCode = $albero->getCodalbero();
- //NODO SOTTOFAMIGLIA
- if (strlen($node) == 4 && strlen($nodeCode) == 6 && substr($nodeCode, 0, 4) == $node) {
- if (substr($nodeCode, 4, 6) == "00" && $albero == null) {
- $html .= $this->getHtmlFigli($nodeCode, $alberi, $articoli);
- } else {
- $html .= "<tr>";
- $html .= " <th colspan=2 class='sottofamiglie'>" . $albero->getTitolo() . "</th>";
- $html .= "</tr>";
- $html .= $this->getHtmlFigli($nodeCode, $alberi, $articoli);
- }
- }
- if (strlen($node) == 6 && strlen($nodeCode) == 8 && substr($nodeCode, 0, 6) == $node) {
- $articolo = $articoli[$albero->getCodarticolo()];
- if ($articolo != null) {
- //stampa listino articolo
- $html .= "<tr>";
- $html .= " <td class ='articoli'>" . $albero->getTitolo() . "</td>";
- $html .= " <td class ='tab_prezzi'>";
- if ($articolo->getListino() != null) {
- $html .= $this->getTableListini($articolo, $articoli);
- }
- $html .= " </td>";
- $html .= "</tr>";
- $html .= $this->getHtmlFigli($nodeCode, $alberi, $articoli);
- if ($articolo->getArticoloTransfert() != null) {
- $html .= "<tr>";
- $html .= "<td class='articoli'>" . $articolo->getArticoloTransfert()->getDesArticolo() . "</td>";
- $html .= "<td class='listini_right' prezzo_agg'>" . $articolo->getArticoloTransfert()->getListino()->getPrezzo1() . " €</td>";
- $html .= "</tr>";
- }
- if ($articolo->getArticoloCorrelato2() != null) {
- $pa = $articoli[$articolo->getArticoloCorrelato2()];
- if ($pa != null) {
- //stampa listino articolo
- $html .= "<tr>";
- $html .= " <td class='articoli' style='padding-left:40px;'>" . $pa->getDesArticolo() . "</td>";
- $html .= " <td class='listini_right prezzo_agg'>";
- $html .= $this->getTableListini($pa, $articoli);
- $html .= " </td></tr>";
- }
- }
- }
- }
- //NODO SOTTOARTICOLO
- if (strlen($node) == 8 && strlen($nodeCode) == 10 && ubstr($nodeCode, 0, 6) == $node) {
- $articolo = $articoli[$albero->getCodArticolo()];
- if ($articolo != null) {
- $html .= "<tr>";
- $html .= "<td class='articoli' style='padding-left:60px;'>" . $albero->getTitolo() . "</td>";
- $html .= "<td class='listini_right prezzo_agg'> </td></tr>";
- }
- }
- }
- return $html;
- }
- private function getTableListini($articolo, $articoli)
- {
- $listiniMap = null;
- $html = "<table width=100% cellpadding=0 cellspacing=0>";
- if ($articolo->getListino() != null) {
- $str = "";
- $prezzo = "";
- $listiniMap["quantita1"] = (int)$articolo->getListino()->getQuantita1();
- $listiniMap["quantita2"] = (int)$articolo->getListino()->getQuantita2();
- $listiniMap["quantita3"] = (int)$articolo->getListino()->getQuantita3();
- $listiniMap["quantita4"] = (int)$articolo->getListino()->getQuantita4();
- $listiniMap["quantita5"] = (int)$articolo->getListino()->getQuantita5();
- $listiniMap["prezzo1"] = "" . $articolo->getListino()->getPrezzo1();
- $listiniMap["prezzo2"] = "" . $articolo->getListino()->getPrezzo2();
- $listiniMap["prezzo3"] = "" . $articolo->getListino()->getPrezzo3();
- $listiniMap["prezzo4"] = "" . $articolo->getListino()->getPrezzo4();
- $listiniMap["prezzo5"] = "" . $articolo->getListino()->getPrezzo5();
- if ($articolo->getListinoPromozionale() != null) {
- $listiniMap["quantita1"] = (int)$articolo->getListinoPromozionale()->getQuantita1();
- $listiniMap["quantita2"] = (int)$articolo->getListinoPromozionale()->getQuantita2();
- $listiniMap["quantita3"] = (int)$articolo->getListinoPromozionale()->getQuantita3();
- $listiniMap["quantita4"] = (int)$articolo->getListinoPromozionale()->getQuantita4();
- $listiniMap["quantita5"] = (int)$articolo->getListinoPromozionale()->getQuantita5();
- $listiniMap["prezzo1"] = "" . $articolo->getListinoPromozionale()->getPrezzo1();
- $listiniMap["prezzo2"] = "" . $articolo->getListinoPromozionale()->getPrezzo2();
- $listiniMap["prezzo3"] = "" . $articolo->getListinoPromozionale()->getPrezzo3();
- $listiniMap["prezzo4"] = "" . $articolo->getListinoPromozionale()->getPrezzo4();
- $listiniMap["prezzo5"] = "" . $articolo->getListinoPromozionale()->getPrezzo5();
- }
- for ($i = 1; $i < 6; $i++) {
- //PRIMA RIGA
- if ($i == 1) {
- if ((int)$listiniMap["quantita" . $i] > 0) {
- $str = "da 1 a " . ((int)$listiniMap["quantita" . $i] - 1);
- $prezzo = (string)number_format((float)$listiniMap["prezzo" . $i], 2, ',', '');
- $html .= "<tr>";
- $html .= " <td class='listini_left'>" . $str . "</td>";
- $html .= " <td class='listini_right'>" . $prezzo . " €</td>";
- $html .= "</tr>";
- } else {
- $str = " ";
- $prezzo = (string)number_format((float)$listiniMap["prezzo" . $i], 2, ',', '');
- $html .= "<tr>";
- $html .= " <td class='listini_left'>" . $str . "</td>";
- $html .= " <td class='listini_right'>" . $prezzo . " €</td>";
- $html .= "</tr>";
- break;
- }
- }
- //ULTIMA RIGA
- if ($i == 5 || (int)$listiniMap["quantita" . ($i + 1)] == 0) {
- $str = "oltre " . (int)$listiniMap["quantita" . $i];
- $prezzo = (string)number_format((float)$listiniMap["prezzo" . ($i + 1)], 2, ',', '');
- $html .= "<tr>";
- $html .= " <td class='listini_left'>" . $str . "</td>";
- $html .= " <td class='listini_right'>" . $prezzo . " €</td>";
- $html .= "</tr>";
- break;
- } //SCAGLIONI
- else {
- $str = "da " . (int)$listiniMap["quantita" . $i] . " a " . (((int)$listiniMap["quantita" . ($i + 1)]) - 1);
- $prezzo = (string)number_format((float)$listiniMap["prezzo" . ($i + 1)], 2, ',', '');
- $html .= "<tr>";
- $html .= " <td class='listini_left'>" . $str . "</td>";
- $html .= " <td class='listini_right'>" . $prezzo . " €</td>";
- $html .= "</tr>";
- }
- }
- }
- $html .= "</table>";
- return $html;
- }
- //------------------------------------------------------------------------------------------------------------------
- /* Funzione che a partire da una transazione fa il login dell'utente
- * Serve per vedere i "miei ordini" dal fototaxi vecchio: dopo aver premuto il pulsante c'è un passaggio obbligato
- * nella orderservlet nella quale si fa un finto login, in realtà viene creata una transazione il cui id viene passato
- * come parametro, richiamando questa funzione si fa il login vero e proprio
- *
- * @param string $idTransazione
- * return array
- */
- public function getUserByTransaction($idTransazione, $host)
- {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $idUtente = TransazioniapplicazioniQuery::create()->filterById($idTransazione)->select("Fkutente")->findOne($con);
- $accountService = new Account_Service();
- $utente = $accountService->loginByUserId($idUtente, $host);
- return $utente;
- }
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @param string $sessionId
- * @param array $utente
- * @throws PropelException
- * @throws ServiceException
- */
- public function createTransaction($sessionId, $utente)
- {
- try {
- $internalTransaction = true;
- $con = Propel::getConnection(DATASOURCE_NAME);
- $con->beginTransaction();
- $config = Zend_Registry::get('Redarea_Configuration');
- $id_prefix = $config->db->id->prefix;
- $transactionId = $id_prefix . uniqid();
- //setto a stinga vuota eventuali parametri facoltativi mancanti
- $utente["Codportale"] = !empty($utente["Codportale"]) ? $utente["Codportale"] : "";
- $utente["Codlaboratorio"] = !empty($utente["Codlaboratorio"]) ? $utente["Codlaboratorio"] : "";
- $utente["Codfotografo"] = !empty($utente["Codfotografo"]) ? $utente["Codfotografo"] : "";
- $utente["Idutente"] = !empty($utente["Idutente"]) ? $utente["Idutente"] : "";
- $transazione = new Transazioniapplicazioni();
- $transazione->setId($transactionId);
- $transazione->setCodportale($utente["Codportale"]);
- $transazione->setCodlaboratorio($utente["Codlaboratorio"]);
- $transazione->setCodfotografo($utente["Codfotografo"]);
- //$transazione->setCodgruppo();
- //$transazione->setCodagente($utente->getCodagente());
- $transazione->setUsername($utente["Username"]);
- $transazione->setFkutente($utente["Idutente"]);
- $transazione->setDatainserimento(date("Y-m-d H:i:s"));
- $transazione->setFkprogetto("");
- $transazione->setClient("FOTOTAXI-OLD");
- $transazione->setSessionid($sessionId);
- $transazione->save($con);
- if ($internalTransaction) {
- $con->commit();
- }
- } catch (Exception $e) {
- if ($internalTransaction) {
- $con->rollBack();
- }
- $this->logger->log(__FILE__, __LINE__, $e->getMessage(), Zend_Log::ERR);
- $this->logger->log(__FILE__, __LINE__, $e->getTraceAsString(), Zend_Log::ERR);
- throw new ServiceException($e->getMessage());
- }
- }
- /**
- * @param array $cartItems
- * @param Promozioni $promozione
- * @param Credits $credits
- * @param bool $applicaPromoPagAgg
- * @return bool
- */
- private function verificaApplicabilitaCondizioni($cartItems, $promozione, $credits, $applicaPromoPagAgg)
- {
- //TODO EARLTP: verificare esistenza funzioni
- $condClassi = $promozione->getCondclassearticoli(); //java: getCondListClassi();
- $condArticoli = $promozione->getCondlistaarticoli(); //java : getCondListaArticoliToList();
- $qtaTotale = 0;
- $importoTotale = 0;
- foreach ($cartItems as $item) {
- if (
- (count($condClassi) == 1 && $condClassi[0] == "" && count($condArticoli) == 0) ||
- ($this->verificaAppartenenzaClassiArticoli($condClassi, $item->getArticolo()->getClasse()) || $this->verificaAppartenenzaClassiArticoli($condArticoli, $item->getArticolo()->getCodArticolo()))
- ) {
- $qtaTotale += $item->getQuantita();
- $importoTotale += $item->getQuantita() * $item->getPrezzo();
- }
- }
- /* nel caso di promozioni:
- - di tipo qta omaggio, 3x2, a prezzo fisso, kit
- - con condizione importo minimo ordine
- - condizione valida su tutte le classi articolo
- l'importo dell'ordine deve essere al netto dello sconto
- */
- $allClasses = (count($condClassi) == 1 && $condClassi[0] == "" && count($condArticoli) == 0);
- if (
- ($promozione->getFlagtipopromozione() == 0 || $promozione->getFlagtipopromozione() == 4 || $promozione->getFlagtipopromozione() == 6) &&
- $allClasses &&
- $promozione->getImpminimoordine() > 0
- ) {
- $sconto = 0;
- if ($promozione->getFlagtipopromozione() == 0) {
- if ($promozione->getPercsconto() == 0) {
- $result = $this->calcolaScontoQtaOmaggio($cartItems, $promozione, $credits, $applicaPromoPagAgg, 0);
- $sconto = (Double)$result["totaleSconto"];
- } else {
- $sconto = $this->calcolaSconto3x2($cartItems, $promozione, $applicaPromoPagAgg);
- }
- } elseif ($promozione->getFlagtipopromozione() == 4) {
- $sconto = $this->calcolaScontoPrezzoFisso($cartItems, $promozione, $applicaPromoPagAgg);
- } elseif ($promozione->getFlagTipoPromozione() == 6) {
- $sconto = $this->calcolaScontoKit($cartItems, $promozione, $credits, $applicaPromoPagAgg, 0);
- }
- $sconto = (float)($sconto + 0.005);
- $importoTotale -= $sconto;
- }
- if ($qtaTotale >= $promozione->getQtaminimaordine() && $importoTotale >= $promozione->getImpminimoordine()) {
- return true;
- }
- return false;
- }
- //------------------------------------------------------------------------------------------------------------------
- //funzioni di test
- //------------------------------------------------------------------------------------------------------------------
- /**
- * @return array
- */
- public function testGetListino()
- {
- $con = Propel::getConnection(DATASOURCE_NAME, Propel::CONNECTION_READ);
- $utente = UtentiQuery::create()->filterByCodportale('rikorda')
- ->filterByUsername('giorgia.gardini@libero.it')
- ->findOne($con);
- $articolo = ArticoliQuery::create()->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getCodLaboratorio())
- ->filterByCodarticolo("10x13-lucida")
- ->findOne($con);
- $fotografo = FotografiQuery::create()->filterByCodportale($utente->getCodportale())
- ->filterByCodlaboratorio($utente->getCodLaboratorio())
- ->filterByCodfotografo($utente->getCodFotografo())
- ->findOne($con);
- $listino = $this->getListino($articolo, $utente, $fotografo);
- return $listino;
- }
- }
Add Comment
Please, Sign In to add comment