issue #0000930 : Gestion des services et des tarifs

This commit is contained in:
Michael RICOIS 2012-10-16 12:57:18 +00:00
parent 3f585797cf
commit 034740a906
10 changed files with 242 additions and 32 deletions

View File

@ -1,5 +0,0 @@
<?php
class Application_Model_ClientsTarif extends Zend_Db_Table_Abstract
{
protected $_name = 'clientsTarif';
}

View File

@ -0,0 +1,5 @@
<?php
class Application_Model_Sdv1ClientsServices extends Zend_Db_Table_Abstract
{
protected $_name = 'clients_services';
}

View File

@ -0,0 +1,5 @@
<?php
class Application_Model_Sdv1ClientsTarifs extends Zend_Db_Table_Abstract
{
protected $_name = 'clients_tarifs';
}

View File

@ -0,0 +1,5 @@
<?php
class Application_Model_Sdv1UtilisateursService extends Zend_Db_Table_Abstract
{
protected $_name = 'utilisateurs_service';
}

View File

@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS `clients_services` (
`code` varchar(20) NOT NULL COMMENT 'Code du service (elements texte sans espace ni caractères spéciaux)',
`label` varchar(100) NOT NULL COMMENT 'Libellé du service',
`idClient` int(11) NOT NULL,
KEY `code` (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

View File

@ -1,18 +1,13 @@
--
-- Structure de la table `clientsTarif`
--
CREATE TABLE IF NOT EXISTS `clientsTarif` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`idClient` int(11) NOT NULL,
`service` char(20) NOT NULL,
`login` char(20) NOT NULL,
`log` char(20) NOT NULL COMMENT 'Element à facturer',
`type` enum('Unitaire','ForfaitLimit','ForfaitIllimit') NOT NULL,
`priceUnit` float NOT NULL DEFAULT '0' COMMENT 'Prix unitaire d''un élément',
`limit` int(11) NOT NULL DEFAULT '0' COMMENT 'Nombre limite de consommation',
`dateDebut` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Date de debut du contrat',
`duree` int(11) NOT NULL COMMENT 'Durée du contrat',
`doublon` enum('jour','mois','period','') NOT NULL COMMENT 'Période de dédoublonnage',
PRIMARY KEY (`id`)
CREATE TABLE IF NOT EXISTS `clients_tarifs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`idClient` int(11) NOT NULL,
`service` char(20) NOT NULL,
`log` char(20) NOT NULL COMMENT 'Element à facturer',
`type` enum('Unitaire','ForfaitLimit','ForfaitNolimit') NOT NULL,
`priceUnit` float NOT NULL DEFAULT '0' COMMENT 'Prix unitaire d''un élément',
`limit` int(11) NOT NULL DEFAULT '0' COMMENT 'Nombre limite de consommation',
`dateDebut` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Date de debut du contrat',
`duree` int(11) NOT NULL COMMENT 'Durée du contrat',
`doublon` enum('jour','mois','period','') NOT NULL COMMENT 'Période de dédoublonnage',
PRIMARY KEY (`id`)
) ENGINE=MyISAM COMMENT='Définition des tarifs pour les clients et services';

View File

@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS `utilisateurs_service` (
`login` varchar(20) NOT NULL,
`serviceCode` varchar(20) NOT NULL COMMENT 'Code du service',
KEY `login` (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

View File

@ -20,4 +20,5 @@ Type[] = "UtilisateursReturn"
Type[] = "ModeleUtilisateurReturn"
Type[] = "ModeleUtilisateur"
Type[] = "ClientTarif"
Type[] = "ClientPrestation"
Type[] = "ClientPrestation"
Type[] = "Service"

View File

@ -1255,7 +1255,7 @@ class Gestion extends WsScore
$db = Zend_Db::factory($this->dbConfig->db->sdv1);
$tarifM = new Application_Model_ClientsTarif($db);
$tarifM = new Application_Model_Sdv1ClientsTarifs($db);
if (!in_array($tarif->log, array_keys($this->listeDroits))) {
throw new SoapFault('ClientTarif', 'log inexistant');
@ -1278,7 +1278,6 @@ class Gestion extends WsScore
$data = array(
'idClient' => $tarif->idClient,
'service' => $tarif->service,
'login' => $tarif->login,
'log' => $tarif->log,
'type' => $tarif->type,
'priceForfait' => $tarif->priceForfait,
@ -1311,7 +1310,7 @@ class Gestion extends WsScore
$db = Zend_Db::factory($this->dbConfig->db->sdv1);
$tarifM = new Application_Model_ClientsTarif($db);
$tarifM = new Application_Model_Sdv1ClientsTarifs($db);
//Au client
$sql = $tarifM->select()
@ -1489,5 +1488,193 @@ class Gestion extends WsScore
return $result;
}
/**
* Define a Service in Client
* @param int $idClient
* @param string $code
* @param string $label
* @throws SoapFault
* @return int
*/
public function setService($idClient, $code, $label)
{
$this->authenticate();
if ($this->tabInfoUser['profil']!='SuperAdministrateur') {
$this->sendError('0902');
}
//Connect to the database
try {
$db = Zend_Db::factory($this->dbConfig->db->sdv1);
$db->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
} catch (Zend_Exception $e) {
throw new SoapFault('ERR', "Application error");
}
try {
$serviceM = new Application_Model_Sdv1ClientsServices();
//Check if code exist in idClient
$sql = $serviceM->select()
->where('idClient=?',$idClient)
->where('code=?',$code);
$row = $serviceM->fetchAll($sql);
if ($row->count()>0) {
$data = array(
'label' => $label,
);
$result = $serviceM->update($data, array('idClient'=>$idClient, 'code'=> $code));
} else {
$data = array(
'code' => $code,
'label' => $label,
'idClient' => $idClient
);
$result = $serviceM->insert($data);
}
} catch (Zend_Db_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
}
return $result;
}
/**
* Set a User in a Service
* @param string $login
* @param string $code
* @throws SoapFault
* @return int
*/
public function setUtilisateurService($login, $code)
{
$this->authenticate();
if ($this->tabInfoUser['profil']!='SuperAdministrateur') {
$this->sendError('0902');
}
//Connect to the database
try {
$db = Zend_Db::factory($this->dbConfig->db->sdv1);
$db->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
} catch (Zend_Exception $e) {
throw new SoapFault('ERR', "Application error");
}
try {
$serviceM = new Application_Model_Sdv1UtilisateursService();
//Check if code exist in idClient
$sql = $serviceM->select()->where('login=?',$login);
$row = $serviceM->fetchAll($sql);
if ($row->count()>0) {
$data = array(
'serviceCode' => $label,
);
$result = $serviceM->update($data, array('login'=>$login));
} else {
$data = array(
'login' => $login,
'serviceCode' => $code,
);
$result = $serviceM->insert($data);
}
} catch (Zend_Db_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
}
return $result;
}
/**
* List Services
* @param int $idClient
* @throws SoapFault
* @return Service
*/
public function getServices($idClient)
{
$this->authenticate();
if ($this->tabInfoUser['profil']!='SuperAdministrateur') {
$this->sendError('0902');
}
//Connect to the database
try {
$db = Zend_Db::factory($this->dbConfig->db->sdv1);
$db->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
} catch (Zend_Exception $e) {
throw new SoapFault('ERR', "Application error");
}
try {
$serviceM = new Application_Model_Sdv1ClientsServices();
$sql = $serviceM->select()->where('idClient=?', $idClient);
$rows = $serviceM->fetchAll($sql);
} catch (Zend_Db_Adapter_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
} catch (Zend_Exception $e) {
throw new SoapFault('ERR', "Application error");
}
$output = array();
if ($rows->count()>0) {
foreach($rows as $item) {
$service = new Service();
$service->code = $item->code;
$service->label = $item->label;
//Get logins
$userserviceM = new Application_Model_Sdv1UtilisateursService();
$sql = $userserviceM->select()->where('code=?',$item->code);
$logins = $userserviceM->fetchAll($sql);
if ($logins->count()>0) {
foreach($logins as $login) {
$service->login[] = $login;
}
}
$output[] = $service;
}
}
return $output;
}
}

View File

@ -454,12 +454,6 @@ class ClientTarif
*/
public $service;
/**
* Identifiant de l'utilisateur
* @var string
*/
public $login;
/**
* Type du forfait ('Unitaire'|'ForfaitLimit'|'ForfaitIllimit')
* @var string
@ -553,3 +547,15 @@ class ClientPrestation
/** @var string */
public $dateFin;
}
class Service
{
/** @var string*/
public $code;
/** @var string*/
public $label;
/** @var string[]*/
public $login;
}