webservice/library/WsScore/WsInterne.php

606 lines
17 KiB
PHP
Raw Normal View History

2010-10-18 13:51:58 +00:00
<?php
2010-10-20 13:32:33 +00:00
require_once realpath(dirname(__FILE__)).'/Types/InterneTypes.php';
2010-10-18 13:51:58 +00:00
class WsInterne
{
2010-10-25 07:33:43 +00:00
protected $dbConfig;
function __construct()
{
$dbConfig = new Zend_Config_Ini(APPLICATION_PATH .
'/configs/databases.ini', APPLICATION_ENV);
$this->dbConfig = $dbConfig->db;
}
2010-10-18 13:51:58 +00:00
/**
* Enregistrement des informations saisie manuellement
* @param string $siret
* @param int $idEntreprise
* @param array $tabInfos
*/
public function setInfosEntrep( $siret, $idEntreprise, $tabInfos )
{
}
2010-10-20 13:32:33 +00:00
/**
* Commande de bilan
* @param InfoCommandeBilan $infoCommande
* @param InfoDemandeur $infoDemandeur
* @return CmdBilanReturn
2010-10-20 13:32:33 +00:00
*/
public function setCmdBilan( InfoCommandeBilan $infoCommande, InfoDemandeur $infoDemandeur )
2010-10-20 13:32:33 +00:00
{
2010-10-20 13:32:33 +00:00
}
2010-10-25 07:33:43 +00:00
/**
* Renvoi des informations sur une commande de bilan
* @param string $reference
* @return CmdBilanReturn
2010-10-25 07:33:43 +00:00
*/
public function getCmdBilan( $reference )
2010-10-25 07:33:43 +00:00
{
}
2010-10-20 13:32:33 +00:00
/**
* Commande d'acte
* @param InfoCommandeActe $infoCommande
* @param InfoDemandeur $infoDemandeur
* @return CmdActeReturn
2010-10-20 13:32:33 +00:00
*/
public function setCmdActe( $infoCommande, $infoDemandeur )
2010-10-20 13:32:33 +00:00
{
}
2010-10-25 07:33:43 +00:00
/**
* Renvoi des informations sur une commande d'acte
* @param string $reference
* @return CmdActeReturn
2010-10-25 07:33:43 +00:00
*/
public function getCmdActe( $reference ){}
2010-10-25 07:33:43 +00:00
2010-10-20 13:32:33 +00:00
/**
* Commande de kbis
* @param InfoCommandeKbis $infoCommande
* @param InfoDemandeur $infoDemandeur
* @return CmdKbisReturn
2010-10-20 13:32:33 +00:00
*/
public function setCmdKbis(InfoCommandeKbis $infoCommande, InfoDemandeur $infoDemandeur )
2010-10-28 16:23:51 +00:00
{
$error = new ErrorType();
$ref = new RefCommande();
//Vérifier les informations
switch($infoCommande->mode)
{
case 'courrier': break;
case 'mail': break;
default:
exit; break;
2010-10-28 16:23:51 +00:00
}
if (empty($infoCommande->siren))
{
$error->errnum = 0;
$error->errmsg = 'Erreur SIREN invalide';
}
else
{
$login = $_SERVER['PHP_AUTH_USER'];
// Insertion des données commande
$dataCommandes = array(
'user_login' => $login,
'user_email' => '',
'type' => 'kbis',
'demandeurReference' => $infoDemandeur->reference,
'demandeurEmail' => $infoDemandeur->email,
'demandeurTel' => $infoDemandeur->tel,
'demandeurNom' => $infoDemandeur->nom,
'demandeurService' => $infoDemandeur->service,
'demandeurSociete' => $infoDemandeur->societe,
'demandeurAdresse' => $infoDemandeur->adresse,
'demandeurCp' => $infoDemandeur->cp,
'demandeurVille' => $infoDemandeur->ville,
'infoCommande' => serialize($infoCommande)
);
try {
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$commande = new Application_Model_Commandes();
$commande_id = $commande->insert($dataCommandes);
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
2010-10-28 16:23:51 +00:00
}
if ($commande_id)
{
//Enregistrement des détails de commande
$dataCommandesKbis = array(
'commande_id' => $commande_id,
'siren' => $infoCommande->siren,
'raisonSociale' => '',
'fichier' => '',
2010-10-28 16:23:51 +00:00
'partenaireRequete' => '',
'partenaireReponse' => '',
);
try {
$commandeKbisTable = new Application_Model_CommandesPieces();
$commandeKbisTable->insert($dataCommandesKbis);
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
2010-10-28 16:23:51 +00:00
}
try {
$row = $commande->find($commande_id);
$data = $row->current();
$ref->reference = $data->id;
$ref->dateCommande = $data->date_added;
$ref->dateMaj = $data->date_updated;
$ref->dateReception = $data->date_closed;
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
2010-10-28 16:23:51 +00:00
$error->errnum = 0;
$error->errmsg = "Commande Introuvable";
}
}
else
{
$error->errnum = 0;
$error->errmsg = "Erreur enregistrement commande";
}
}
$output = new CmdKbisReturn();
$cmd = new CmdKbisDetail();
$cmd->infoCommande = $infoCommande;
$cmd->infoDemandeur = $infoDemandeur;
2010-11-08 11:30:49 +00:00
$cmd->refCommande = $ref;
$output->commande = $cmd;
2010-10-28 16:23:51 +00:00
$output->error = $error;
return $output;
}
2010-10-20 13:32:33 +00:00
2010-10-25 07:33:43 +00:00
/**
* Renvoi des informations sur une commande de Kbis
* @param string $reference
* @return CmdKbisReturn
2010-10-25 07:33:43 +00:00
*/
public function getCmdKbis( $reference ){}
2010-10-20 13:32:33 +00:00
/**
* Commande de statut association
2010-10-25 07:33:43 +00:00
* @param InfoCommandeAsso $infoCommande
2010-10-20 13:32:33 +00:00
* @param InfoDemandeur $infoDemandeur
* @return CmdAssoReturn
2010-10-20 13:32:33 +00:00
*/
public function setCmdAsso( $infoCommande, $infoDemandeur ){}
2010-10-20 13:32:33 +00:00
/**
2010-10-25 07:33:43 +00:00
* Renvoi des informations sur une commande association
2010-10-20 13:32:33 +00:00
* @param string $reference
* @return CmdAssoReturn
2010-10-20 13:32:33 +00:00
*/
public function getCmdAsso( $reference ){}
2010-10-20 13:32:33 +00:00
/**
2010-10-25 07:33:43 +00:00
* Commande de privilèges et nantissements par email
* @param InfoCommandePieces $infoCommande
* @param InfoDemandeur $infoDemandeur
* @return CmdPiecesReturn
2010-10-20 13:32:33 +00:00
*/
public function setCmdPieces( $infoCommande, $infoDemandeur )
2010-10-25 07:33:43 +00:00
{
2010-10-25 07:33:43 +00:00
$error = new ErrorType();
$ref = new RefCommande();
2010-10-25 07:33:43 +00:00
if (!empty($infoCommande->siren))
{
$login = $_SERVER['PHP_AUTH_USER'];
//Vérification SIREN
//Vérification email - Si infoDemandeur->email vide alors on prend
2010-10-28 16:23:51 +00:00
//user_email
2010-10-25 07:33:43 +00:00
// Insertion des données commande
$dataCommandes = array(
'user_login' => $login,
'user_email' => '',
'type' => 'pieces',
'demandeurReference' => $infoDemandeur->reference,
'demandeurEmail' => $infoDemandeur->email,
'demandeurTel' => $infoDemandeur->tel,
'demandeurNom' => $infoDemandeur->nom,
'demandeurService' => $infoDemandeur->service,
'demandeurSociete' => $infoDemandeur->societe,
'demandeurAdresse' => $infoDemandeur->adresse,
'demandeurCp' => $infoDemandeur->cp,
'demandeurVille' => $infoDemandeur->ville,
2010-10-26 15:42:18 +00:00
'infoCommande' => serialize($infoCommande)
2010-10-25 07:33:43 +00:00
);
try {
2010-10-26 15:42:18 +00:00
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$commande = new Application_Model_Commandes();
2010-10-28 16:23:51 +00:00
$commande_id = $commande->insert($dataCommandes);
2010-10-25 07:33:43 +00:00
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
2010-10-25 07:33:43 +00:00
}
2010-10-28 16:23:51 +00:00
if ($commande_id)
2010-10-25 07:33:43 +00:00
{
//Enregistrement des détails de commande
$dataCommandesPieces = array(
2010-10-28 16:23:51 +00:00
'commande_id' => $commande_id,
2010-10-25 07:33:43 +00:00
'siren' => $infoCommande->siren,
'raisonSociale' => '',
2010-10-26 15:42:18 +00:00
'fichier' => '',
2010-10-25 07:33:43 +00:00
);
try {
2010-10-26 15:42:18 +00:00
$commandePieces = new Application_Model_CommandesPieces();
$commandePieces->insert($dataCommandesPieces);
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
2010-10-26 15:42:18 +00:00
}
try {
2010-10-28 16:23:51 +00:00
$row = $commande->find($commande_id);
2010-10-26 15:42:18 +00:00
$data = $row->current();
$ref->reference = $data->id;
$ref->dateCommande = $data->date_added;
$ref->dateMaj = $data->date_updated;
$ref->dateReception = $data->date_closed;
2010-10-25 07:33:43 +00:00
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
2010-10-26 15:42:18 +00:00
$error->errnum = 0;
$error->errmsg = "Commande Introuvable";
2010-10-25 07:33:43 +00:00
}
}
else
{
$error->errnum = 0;
$error->errmsg = "Erreur enregistrement commande";
}
}
else
{
$error->errnum = 0;
$error->errmsg = 'Erreur SIREN invalide';
}
$output = new CmdPiecesReturn();
$cmd = new CmdPiecesDetail();
$cmd->infoCommande = $infoCommande;
$cmd->infoDemandeur = $infoDemandeur;
2010-11-08 11:30:49 +00:00
$cmd->refCommande = $ref;
2010-10-25 07:33:43 +00:00
$output->error = $error;
return $output;
}
2010-10-20 13:32:33 +00:00
/**
2010-10-25 07:33:43 +00:00
* Renvoi des informations sur une commande pièces
2010-10-20 13:32:33 +00:00
* @param string $reference
* @return CmdPiecesReturn
2010-10-20 13:32:33 +00:00
*/
public function getCmdPieces( $reference )
{
list($typeCommande, $idCommande) = explode('-', $reference);
try {
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$commandeTable = new Application_Model_Commandes();
$select = $commandeTable->select()
->where('type = ?', 'pieces')
->where('id = ?', $idCommande);
$commandeRowset = $commandeTable->fetchAll($select);
}
catch (Zend_Db_Adapter_Exception $e)
{
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
}
$error = new ErrorType();
$ref = new RefCommande();
$infoCommande = new InfoCommandePieces();
$infoDemandeur = new InfoDemandeur();
if ( $commandeRowset->count()>0 )
{
$commande = $commandeRowset->current();
$selectEven = $commandeTable->select()
->order('date_added DESC')->limit(1);
$evenRowset = $commande->findDependentRowset(
'Application_Model_CommandesEven', null, $selectEven);
$info = '';
if($evenRowset->count()>0){
$even = $evenRowset->current();
$info = $even->commentaire;
}
$ref->reference = strtoupper($commande->type).'-'.$commande->id;
$ref->dateCommande = $commande->date_added;
$ref->dateMaj = $commande->date_updated;
$ref->dateReception = $commande->date_closed;
$ref->info = $info;
$ref->fichier = ''; // @todo : Détecter le fichier
$ref->login = $commande->user_login;
$infoCommande = unserialize($commande->infoCommande);
$infoDemandeur->reference = $commande->demandeurReference;
$infoDemandeur->email = $commande->demandeurEmail;
$infoDemandeur->tel = $commande->demandeurTel;
$infoDemandeur->nom = $commande->demandeurNom;
$infoDemandeur->service = $commande->demandeurService;
$infoDemandeur->societe = $commande->demandeurSociete;
$infoDemandeur->adresse = $commande->demandeurAdresse;
$infoDemandeur->cp = $commande->demandeurCp;
$infoDemandeur->ville = $commande->demandeurVille;
}
else
{
$error->errnum = 0;
$error->errmsg = 'Référence inconnue';
}
$output = new CmdPiecesReturn();
$cmd = new CmdPiecesDetail();
2010-11-08 11:30:49 +00:00
$cmd->refCommande = $ref;
$cmd->infoCommande = $infoCommande;
$cmd->infoDemandeur = $infoDemandeur;
$output->commande = $cmd;
$output->error = $error;
return $output;
}
2010-10-20 13:32:33 +00:00
/**
* Retourne la liste des commandes de pièces ainsi que leur détails
* @param CmdFiltrePieces $filtre
2010-10-25 07:33:43 +00:00
* @param int $position
* @param int $nbRep
* @return ListeCmdPiecesReturn
2010-10-20 13:32:33 +00:00
*/
public function getListeCmdPieces( $filtre, $position = 0, $nbRep = 20 )
2010-10-26 15:42:18 +00:00
{
$error = new ErrorType();
//Traitements des filtres pour générer la requête SQL
//Selection
$nbCommandes = 0;
try
{
2010-10-26 15:42:18 +00:00
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$commandeTable = new Application_Model_Commandes();
$select = $commandeTable->select()->where('type = ?', 'pieces');
$countRowset = $commandeTable->fetchAll($select);
$nbCommandes = $countRowset->count();
$select->order('date_added DESC')->limit($nbRep, $position);
$commandeRowset = $commandeTable->fetchAll($select);
2010-10-26 15:42:18 +00:00
}
catch (Zend_Db_Adapter_Exception $e)
{
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
$error->errnum = 1;
$error->errmsg = 'Erreur';
2010-10-26 15:42:18 +00:00
}
if ( $commandeRowset->count()>0 )
2010-10-26 15:42:18 +00:00
{
$liste = array();
foreach ($commandeRowset as $commande)
{
$selectEven = $commandeTable->select()
2010-10-28 16:23:51 +00:00
->order('date_added DESC')->limit(1);
$evenRowset = $commande->findDependentRowset(
'Application_Model_CommandesEven', null, $selectEven);
2010-10-26 15:42:18 +00:00
$info = '';
if($evenRowset->count()>0){
$even = $evenRowset->current();
$info = $even->commentaire;
2010-10-26 15:42:18 +00:00
}
2010-10-26 15:42:18 +00:00
$ref = new RefCommande();
$ref->reference = strtoupper($commande->type).'-'.$commande->id;
$ref->dateCommande = $commande->date_added;
$ref->dateMaj = $commande->date_updated;
$ref->dateReception = $commande->date_closed;
2010-10-26 15:42:18 +00:00
$ref->info = $info;
$ref->fichier = ''; // @todo : Détecter le fichier
$ref->login = $commande->user_login;
$infoCommande = new InfoCommandePieces();
$infoCommande = unserialize($commande->infoCommande);
$infoDemandeur = new InfoDemandeur();
$infoDemandeur->reference = $commande->demandeurReference;
$infoDemandeur->email = $commande->demandeurEmail;
$infoDemandeur->tel = $commande->demandeurTel;
$infoDemandeur->nom = $commande->demandeurNom;
$infoDemandeur->service = $commande->demandeurService;
$infoDemandeur->societe = $commande->demandeurSociete;
$infoDemandeur->adresse = $commande->demandeurAdresse;
$infoDemandeur->cp = $commande->demandeurCp;
$infoDemandeur->ville = $commande->demandeurVille;
$cmd = new CmdPiecesDetail();
$cmd->refCommande = $ref;
$cmd->infoCommande = $infoCommande;
$cmd->infoDemandeur = $infoDemandeur;
$liste[] = $cmd;
2010-10-26 15:42:18 +00:00
}
}
$output = new ListeCmdPiecesReturn();
2010-10-26 15:42:18 +00:00
$output->error = $error;
$output->nbCommandes = $nbCommandes;
$output->liste = $liste;
2010-10-26 15:42:18 +00:00
return $output;
}
2010-10-20 13:32:33 +00:00
/**
* Liste des bilans
* @param string $siren
* @param string $waldec
* @param int $idEntreprise
* @return ListeBilan
*/
2010-10-25 07:33:43 +00:00
public function getListeBilan( $siren, $waldec = null, $idEntreprise = null ){}
2010-10-20 13:32:33 +00:00
/**
* Liste des actes
* @param string $siren
* @return ListeActe
*/
2010-10-25 07:33:43 +00:00
public function getListeActe( $siren ){}
/**
* Retourne la liste des statuts de commande
* @param string $type
* @return CmdStatut[]
2010-10-25 07:33:43 +00:00
*/
public function getListeCmdStatut( $type )
2010-10-25 07:33:43 +00:00
{
Zend_Registry::get('WsLogger')->info("getListeStatut - ".$type);
try {
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
2010-10-26 15:42:18 +00:00
$dbStatut = new Application_Model_CommandesStatut();
2010-10-25 07:33:43 +00:00
$result = $dbStatut->fetchAll(array("commande_type = '$type'"));
}
catch (Zend_Db_Adapter_Exception $e)
{
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
2010-10-25 07:33:43 +00:00
}
$listeStatut = array();
if (count($result)>0)
{
foreach($result as $r)
{
$statut = new CmdStatut();
2010-10-25 07:33:43 +00:00
$statut->code = $r['code'];
$statut->lib = $r['libelle'];
$listeStatut[] = $statut;
}
}
return $listeStatut;
}
/**
* Spécifier un état défini pour une commande
2010-10-28 16:23:51 +00:00
* (avec déclenchement d'une action)
* @param int $reference
2010-10-26 15:42:18 +00:00
* @param int $statutCode
* @return bool
*/
public function setCmdStatut( $reference, $statutCode)
2010-10-26 15:42:18 +00:00
{
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$dbStatut = new Application_Model_CommandesStatut();
2010-10-28 16:23:51 +00:00
$row = $dbStatut->fetchRow(array("code = '$statutCode'"));
if ( count($row)>0 && $this->setCommandeEven($reference, $row['lib']) )
2010-10-26 15:42:18 +00:00
{
2010-10-28 16:23:51 +00:00
if (!empty($row['action'])){
switch($row['action']){
2010-10-26 15:42:18 +00:00
case 'CLOSE':
//date_closed
break;
}
}
return true;
} else {
return false;
}
}
/**
* Spécifier un état pour une commande
2010-10-28 16:23:51 +00:00
* @param int $reference
2010-10-25 07:33:43 +00:00
* @param string $comment
* @return bool
*/
public function setCmdEven ( $reference, $comment )
2010-10-25 07:33:43 +00:00
{
$login = $_SERVER['PHP_AUTH_USER'];
2010-10-28 16:23:51 +00:00
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
2010-10-25 07:33:43 +00:00
try {
2010-10-28 16:23:51 +00:00
//Vérifier que la commande existe avec la référence fournie
$commandeTable = new Application_Model_Commandes();
$commandeRowset = $commandeTable->find($reference);
if ($commandeRowset->count()>0)
{
$commande = $commandeRowset->current();
//Enregistrer l'événement
$commandeEvenTable = new Application_Model_CommandesEven();
$insert = $commandeEvenTable->createRow();
$insert->commande_id = $commande->id;
$insert->commentaire = $comment;
$insert->user_login = $login;
$insert->save();
//Mettre à jour la commande
$commande->date_updated = date('Y-m-d H:i:s');
$commande->save();
return true;
} else {
return false;
}
2010-10-25 07:33:43 +00:00
}
catch (Zend_Db_Adapter_Exception $e)
{
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
2010-10-25 07:33:43 +00:00
return false;
}
}
/**
* Ajout du nom de fichier liée à la commande
2010-10-28 16:23:51 +00:00
* @param int $reference
2010-10-25 07:33:43 +00:00
* @param string $filename
2010-10-28 16:23:51 +00:00
* @return bool
2010-10-25 07:33:43 +00:00
*/
public function setCmdDocument( $reference, $filename )
2010-10-20 13:32:33 +00:00
{
2010-10-28 16:23:51 +00:00
$login = $_SERVER['PHP_AUTH_USER'];
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
try {
//Vérifier que la commande existe avec la référence fournie
$commandeTable = new Application_Model_Commandes();
$commandeRowset = $commandeTable->find($reference);
if ($commandeRowset->count()>0)
{
$commande = $commandeRowset->current();
switch($commande->type)
{
case 'pieces':
$infoCommandePieces = $commande->findDependentRowset('Application_Model_CommandesPieces');
if ($infoCommandePieces->count()>0)
{
//Update informations pieces
$commandePieces = $infoCommandePieces->current();
$commandePieces->fichier = $filename;
$commandePieces->save();
//Mettre à jour la commande
$commande->date_updated = date('Y-m-d H:i:s');
$commande->save();
return true;
}
break;
case 'default':
return false;
break;
}
} else {
return false;
}
}
catch (Zend_Db_Adapter_Exception $e)
{
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
2010-10-28 16:23:51 +00:00
return false;
}
2010-10-20 13:32:33 +00:00
}
2010-10-18 13:51:58 +00:00
}