authenticate(); $this->permission('UPLOADBILAN'); // Check source if (in_array($source, array('extranet', 'infogreffe'))) { } // Check Siren else { if (strlen($siren) != 9 || intval($siren) == 0) { throw new SoapFault('ERR', "SIREN invalid"); } $iInsee = new Metier_Insee_MInsee(); $result = $iInsee->getIdentiteLight($siren); if (count($result) == 0) { throw new SoapFault('ERR', "SIREN invalid"); } } $refCommande = uniqid(); $data = array( 'refCommande' => $refCommande, 'siren' => $siren, 'userId' => $this->User->id, 'bilanConfidentiel' => $private, 'bilanSource' => $source, 'bilanCloture' => $date, 'bilanType' => $type, 'dateInsert' => date('YmdHis'), ); try { $commandeM = new Application_Model_Sdv1OrderBilanInput(); $commandeM->insert($data); return $refCommande; } catch (Zend_Db_Exception $e) { if ($this->User->idClient==1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } } /** * Send file content as base64 * @param string $ref * Order reference * @param string $file * Base64 string of file content * @param string $hash * MD5 du contenu du fichier * @throws SoapFault * @return boolean */ public function setBilanInputContent($ref, $file, $hash = null) { $this->authenticate(); $this->permission('UPLOADBILAN'); // Ref exist $commandeM = new Application_Model_Sdv1OrderBilanInput(); $commandeSql = $commandeM->select()->where('refCommande=?', $ref); $commandeResult = $commandeM->fetchRow($commandeSql); if ($commandeResult === false) { throw new SoapFault('ERR', "Ref not exist"); } // Generate filename $siren = $commandeResult->siren; $type = $commandeResult->type; $cloture = $commandeResult->bilanCloture; $ref = $commandeResult->refCommande; $filename = $siren.'_'.$type.'_'.$cloture.'_'.$ref.'.pdf'; // Save file $decoded = base64_decode($file); if ($decoded === false) { throw new SoapFault('ERR', "Error decoding"); } $c = Zend_Registry::get('config'); $path = $c->profil->path->shared.'/datafile/clients/bilansext/send'; $write = file_put_contents($path.'/'.$filename, $decoded); if ($write === false) { throw new SoapFault('ERR', "Error writing"); } // Check MD5 if (!empty($hash)) { if (md5_file($path.'/'.$filename) != $hash) { throw new SoapFault('ERR', "File hash verification failed"); } } // Sauvegarde database $data = array( 'bilanFileSent' => date('YmdHis'), 'bilanFile' => $filename, ); try { $commandeM->update($data, 'refCommande="'.$commandeResult->refCommande.'"'); return true; } catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } return false; } /** * Financial account : Tag file is sent * @param string $ref * @param string $filename * @throws SoapFault * @return boolean */ public function setBilanInputFile($ref, $filename) { $this->authenticate(); $this->permission('UPLOADBILAN'); // Check source = extranet /*if ($this->authApp != 'extranet') { throw new SoapFault('ERR', "Not authorize"); }*/ $data = array( 'bilanFileSent' => date('YmdHis'), 'bilanFile' => $filename, ); try { $commandeM = new Application_Model_Sdv1OrderBilanInput(); $commandeM->update($data, 'refCommande="'.$ref.'"'); return true; } catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } return false; } /** * Liste des commandes de saisie de bilan * @param string $month * @throws SoapFault * @return BilanInput[] */ public function getBilanInputList($month = null) { $this->authenticate(); if ($month === null) { $month = date('Y-m'); } $dateStart = $month.'-01 00:00:00'; $dateEnd = $month.'-31 23:59:59'; $list = array(); try { $commandeM = new Application_Model_Sdv1OrderBilanInput(); $sql = $commandeM->select() ->where('userId=?', $this->User->id) ->where('dateInsert BETWEEN "'.$dateStart.'" AND "'.$dateEnd.'"') ->order('dateInsert DESC'); $result = $commandeM->fetchAll($sql); if (count($result) > 0) { foreach($result as $item) { $cmd = new BilanInput(); $cmd->Reference = strtoupper($item->refCommande); $cmd->Siren = $item->siren; $cmd->BilanFileRecv = $item->bilanFileRecv; $cmd->BilanCloture = $item->bilanCloture; $cmd->BilanType = $item->bilanType; $cmd->ErreurDate = $item->erreurDate; $cmd->ErreurLabel = $item->erreurTxt; $cmd->DateInsert = $item->dateInsert; $cmd->DateSaisie = $item->dateSaisie; $list[] = $cmd; } } } catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } return $list; } /** * Détail d'un bilan en commande saisie * @param string $ref * @throws SoapFault * @return BilanInput|NULL */ protected function getBilanInputDetail($ref) { $this->authenticate(); try { $commandeM = new Application_Model_Sdv1OrderBilanInput(); $sql = $commandeM->select()->where('userId=?', $this->User->id)->where('refCommande=?', $ref); $item = $commandeM->fetchRow($sql); if ($item !== null) { $cmd = new BilanInput(); $cmd->Reference = strtoupper($item->refCommande); $cmd->Siren = $item->siren; $cmd->BilanFileRecv = $item->bilanFileRecv; $cmd->BilanCloture = $item->bilanCloture; $cmd->BilanType = $item->bilanType; $cmd->ErreurDate = $item->erreurDate; $cmd->ErreurLabel = $item->erreurTxt; $cmd->DateInsert = $item->dateInsert; $cmd->DateSaisie = $item->dateSaisie; return $cmd; } } catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } return null; } /** * Liste des commandes KBIS * @param string $month * @throws SoapFault * @return PieceKbis[] */ public function getKbisList($month = null) { $this->authenticate(); if ($month === null) { $month = date('Y-m'); } $dateStart = $month.'-01 00:00:00'; $dateEnd = $month.'-31 23:59:59'; $list = array(); try { $commandeM = new Application_Model_Sdv1GreffeCommandesKb(); $sql = $commandeM->select() ->where('login=?', $this->User->login) ->where('dateInsert BETWEEN "'.$dateStart.'" AND "'.$dateEnd.'"') ->order('dateInsert DESC'); $result = $commandeM->fetchAll($sql); if (count($result) > 0) { foreach($result as $item) { $cmd = new PieceKbis(); $cmd->Reference = strtoupper($item->refCommande); $cmd->Mode = $item->mode; $cmd->Error = $item->cmdError; $cmd->CompanyName = $item->raisonSociale; $cmd->CompanySiren = $item->siren; $cmd->DateInsert = $item->dateInsert; $cmd->DateEnvoi = $item->dateEnvoi; $list[] = $cmd; } } } catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } return $list; } /** * Detail de la commande d'un KBIS * @param unknown $ref * @throws SoapFault * @return BilanInput|NULL */ protected function getKbisDetail($ref) { $this->authenticate(); try { $commandeM = new Application_Model_Sdv1GreffeCommandesKb(); $sql = $commandeM->select()->where('login=?', $this->User->login)->where('refCommande=?', $ref); $item = $commandeM->fetchRow($sql); if ($item !== null) { $cmd = new BilanInput(); $cmd->Reference = strtoupper($item->refCommande); $cmd->Mode = $item->mode; $cmd->Error = $item->cmdError; $cmd->CompanyName = $item->raisonSociale; $cmd->CompanySiren = $item->siren; $cmd->DateInsert = $item->dateInsert; $cmd->DateEnvoi = $item->dateEnvoi; return $cmd; } } catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } return null; } protected function getKbisFile($ref) { $this->authenticate(); // --- Paramètres $hostname = 'http://'.$_SERVER['SERVER_NAME']; if ($_SERVER['SERVER_PORT']!='80'){ $hostname.= ':'.$_SERVER['SERVER_PORT']; } $c = Zend_Registry::get('config'); $path = realpath($c->profil->path->shared).'/datafile/kbis'; $file = null; // --- Lecture des informations de la commande try { $commandeM = new Application_Model_Sdv1GreffeCommandesKb(); $sql = $commandeM->select()->where('login=?', $this->User->login)->where('refCommande=?', $ref); $item = $commandeM->fetchRow($sql); if ($item !== null) { $cmd = new BilanInput(); $cmd->Reference = strtoupper($item->refCommande); $cmd->Mode = $item->mode; $cmd->Error = $item->cmdError; $cmd->CompanyName = $item->raisonSociale; $cmd->CompanySiren = $item->siren; $cmd->DateInsert = $item->dateInsert; $cmd->DateEnvoi = $item->dateEnvoi; return $cmd; } } catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } } /** * Liste des commandes d'acte infogreffe * @param string $month * @throws SoapFault * @return Acte[] */ public function getActeList($month = null) { $this->authenticate(); if ($month === null) { $month = date('Y-m'); } $dateStart = $month.'-01 00:00:00'; $dateEnd = $month.'-31 23:59:59'; $list = array(); try { $commandeM = new Application_Model_Sdv1GreffeCommandesAc(); $sql = $commandeM->select() ->where('login=?', $this->User->login) ->where('dateInsert BETWEEN "'.$dateStart.'" AND "'.$dateEnd.'"') ->order('dateInsert DESC'); $result = $commandeM->fetchAll($sql); if (count($result) > 0) { foreach($result as $item) { $cmd = new Acte(); $cmd->Reference = strtoupper($item->refCommande); $cmd->Mode = $item->mode; $cmd->Error = $item->cmdError; $cmd->DocLabel = ''; //@todo : Génére le libellé du document $cmd->DocDepotNum = $item->depotNum; $cmd->DocDepotDate = $item->depotDate; $cmd->DocActeNum = $item->acteNum; $cmd->DocActeType = $item->acteType; $cmd->DocActeDate = $item->acteDate; $cmd->CompanyName = $item->raisonSociale; $cmd->CompanySiren = $item->siren; $cmd->DateInsert = $item->dateInsert; $cmd->DateEnvoi = $item->dateEnvoi; $list[] = $cmd; } } } catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } return $list; } protected function getActeDetail($ref){} protected function getActeFile($ref){} /** * Liste des commandes de bilan infogreffe * @param string $month * @throws SoapFault * @return Bilan[] */ public function getBilanList($month = null) { $this->authenticate(); if ($month === null) { $month = date('Y-m'); } $dateStart = $month.'-01 00:00:00'; $dateEnd = $month.'-31 23:59:59'; $list = array(); try { $commandeM = new Application_Model_Sdv1GreffeCommandesBi(); $sql = $commandeM->select() ->where('login=?', $this->User->login) ->where('dateInsert BETWEEN "'.$dateStart.'" AND "'.$dateEnd.'"') ->order('dateInsert DESC'); $result = $commandeM->fetchAll($sql); if (count($result) > 0) { foreach($result as $item) { $cmd = new Bilan(); $cmd->Reference = strtoupper($item->refCommande); $cmd->Mode = $item->mode; $cmd->Error = $item->cmdError; $cmd->DocBilanCloture = $item->bilanCloture; $cmd->DocBilanType = $item->bilanType; $cmd->CompanyName = $item->raisonSociale; $cmd->CompanySiren = $item->siren; $cmd->DateInsert = $item->dateInsert; $cmd->DateEnvoi = $item->dateEnvoi; $list[] = $cmd; } } } catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } return $list; } /** * Détail de la commande de bilan Infogreffe * @param unknown $ref * @throws SoapFault * @return BilanInput|NULL */ protected function getBilanDetail($ref) { $this->authenticate(); try { $commandeM = new Application_Model_Sdv1GreffeCommandesKb(); $sql = $commandeM->select()->where('login=?', $this->User->login)->where('refCommande=?', $ref); $item = $commandeM->fetchRow($sql); if ($item !== null) { $cmd = new BilanInput(); $cmd->Reference = strtoupper($item->refCommande); $cmd->Mode = $item->mode; $cmd->Error = $item->cmdError; $cmd->DocBilanCloture = $item->bilanCloture; $cmd->DocBilanType = $item->bilanType; $cmd->CompanyName = $item->raisonSociale; $cmd->CompanySiren = $item->siren; $cmd->DateInsert = $item->dateInsert; $cmd->DateEnvoi = $item->dateEnvoi; return $cmd; } } catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } return null; } protected function getBilanFile($ref){} protected function setInvestigation() { $this->authenticate(); $this->permission('enquetec'); //Table pour le stockage des demandes d'investigation } /** * Commandes de statuts association * @param string $month * @throws SoapFault * @return AssoStatut[] */ public function getAssoStatut($month = null) { $this->authenticate(); if ($month === null) { $month = date('Y-m'); } $dateStart = $month.'-01 00:00:00'; $dateEnd = $month.'-31 23:59:59'; $list = array(); try { $commandeM = new Application_Model_Sdv1GreffeCommandesKb(); $sql = $commandeM->select() ->where('login=?', $this->User->login) ->where('dateInsert BETWEEN "'.$dateStart.'" AND "'.$dateEnd.'"') ->order('dateInsert DESC'); $result = $commandeM->fetchAll($sql); if (count($result) > 0) { foreach($result as $item) { $cmd = new AssoStatut(); $cmd->Reference = strtoupper($item->refCommande); $cmd->Mode = $item->mode; $cmd->Error = $item->cmdError; $cmd->CompanyName = $item->companyName; $cmd->CompanyId = $item->companyId; $cmd->CompanyIdType = $item->typeId; $cmd->DateInsert = $item->dateInsert; $cmd->DateEnvoi = $item->dateDone; $list[] = $cmd; } } } catch (Zend_Db_Exception $e) { if ($this->User->idClient == 1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } return $list; } }