extranet/application/controllers/DashboardController.php

394 lines
12 KiB
PHP

<?php
class DashboardController extends Zend_Controller_Action
{
public function init()
{
require_once 'Scores/WsScores.php';
require_once 'Scores/Utilisateur.php';
}
public function preDispatch()
{
$user = new Utilisateur();
if (!$user->checkModeEdition() && $user->getIdClient()!=1 ){
$this->_forward('perms', 'error');
}
}
/**
* Affichage des différents liens d'administration
*/
public function indexAction()
{
$liens = array(
0 => array(
'libelle' => 'Gestion des clients',
'url' => $this->view->url(array('action'=>'clients')),
),
1 => array(
'libelle' => 'Créer un client',
'url' => $this->view->url(array('action'=>'client')),
),
2 => array(
'libelle' => 'Gestion des commandes',
'url' => $this->view->url(array('action'=>'commandes')),
),
);
$this->view->assign('Liens', $liens);
}
/**
* Gestion des commandes de l'extranet
* Type : greffes | kbis | graydon | giant
*/
public function commandesAction()
{
$this->view->headScript()->appendFile('/themes/default/scripts/dashboard.js', 'text/javascript');
$request = $this->getRequest();
$type = $request->getParam('type', '');
$user = new Utilisateur();
$typesCommande = array('kbis', 'greffes');
if (in_array($type, $typesCommande)){
require_once 'Scores/GestionCommandes.php';
switch($type){
case 'kbis':
$num = $request->getParam('num');
$num = str_replace(' ', '', $num);
$etat = $request->getParam('etat');
$mode = $request->getParam('mode', '-');
$date = $request->getParam('date');
$modeSelect = array(
'-' => array('value'=>'-', 'select'=>'', 'affichage'=>''),
'G' => array('value'=>'G', 'select'=> '', 'affichage'=>'courrier infogreffe'),
'C' => array('value'=>'C', 'select'=> '', 'affichage'=>'courrier S&amp;D'),
'E' => array('value'=>'E', 'select'=> '', 'affichage'=>'e-mail'),
);
$modeSelect[$mode]['select'] = ' selected';
$gestionCommande = new GestionCommande();
$status = $gestionCommande->listStatus();
$etatSelect = array();
$etatSelect[] = array('value'=>0, 'select'=>'', 'affichage'=>'');
foreach($status as $item){
$select = '';
if ($item['id']==$etat){
$select = ' selected';
}
$etatSelect[] = array('value'=>$item['id'], 'select'=>$select, 'affichage'=>$item['libStatut']);
}
//Valeur pour la sélection des dates
$dateSelect = array();
$dateToday = date('m');
$dateIntervalle = 12;
if ($user->checkModeEdition()){
$dateIntervalle = 24;
}
for($i=$dateToday-$dateIntervalle; $i<=$dateToday; $i++) {
$dateTime = mktime(0, 0, 0, $i+1, 0, date('Y'));
$selected = '';
if ($date=='' && $i==$dateToday ){
$selected = 'selected';
}
if ($date!='' && $dateTime==$date){
$selected = 'selected';
}
$dateSelect[] = array(
'value' => $dateTime,
'select' => $selected,
'affichage' => date('m/Y', $dateTime)
);
}
$this->view->assign('dateSelect', $dateSelect);
$this->view->assign('etatSelect', $etatSelect);
$this->view->assign('modeSelect', $modeSelect);
$this->view->assign('num', $num);
if (!empty($num)){
if (preg_match('/[0-9]{9}/', $num)){
$listCommandes = $gestionCommande->listCommandesKbisBySiren($num);
} elseif(substr($num,0,1)=='K'){
$listCommandes = $gestionCommande->listCommandesKbisByNum($num);
}
} elseif (!empty($date)) {
$listCommandes = $gestionCommande->listCommandesKbis($date, $etat, $mode);
}
break; //Fin Gestion Kbis
case 'greffes':
$num = $request->getParam('num');
$num = str_replace(' ', '', $num);
$etat = $request->getParam('etat');
$mode = $request->getParam('mode', '-');
$date = $request->getParam('date');
$login = $request->getParam('login');
if (empty($mode) && !empty($num)) $mode = substr($num,0,1);
$modeSelect = array(
'-' => array('value'=>'-', 'select'=>'', 'affichage'=>''),
'G' => array('value'=>'G', 'select'=> '', 'affichage'=>'courrier infogreffe'),
'C' => array('value'=>'C', 'select'=> '', 'affichage'=>'courrier S&amp;D'),
'E' => array('value'=>'E', 'select'=> '', 'affichage'=>'e-mail'),
);
$modeSelect[$mode]['select'] = ' selected';
$gestionCommande = new GestionCommande();
//Liste des états possible pour les commandes
$status = $gestionCommande->listAllStatus();
$etatSelect = array();
$etatSelect[] = array('value'=>0, 'select'=>'', 'affichage'=>'');
foreach($status as $item){
$select = '';
if ($item['id']==$etat){
$select = ' selected';
}
$etatSelect[] = array(
'value'=>$item['id'],
'select'=>$select,
'affichage'=>$item['libStatut']
);
}
//Valeur pour la sélection des dates
$dateSelect = array();
$dateToday = date('m');
$dateIntervalle = 12;
if ($user->checkModeEdition()){
$dateIntervalle = 24;
}
for($i=$dateToday-$dateIntervalle; $i<=$dateToday; $i++) {
$dateTime = mktime(0, 0, 0, $i+1, 0, date('Y'));
$selected = '';
if ($date=='' && $i==$dateToday ){
$selected = 'selected';
}
if ($date!='' && $dateTime==$date){
$selected = 'selected';
}
$dateSelect[] = array(
'value' => $dateTime,
'select' => $selected,
'affichage' => date('m/Y', $dateTime)
);
}
$this->view->assign('dateSelect', $dateSelect);
$this->view->assign('etatSelect', $etatSelect);
$this->view->assign('modeSelect', $modeSelect);
$this->view->assign('num', $num);
$this->view->assign('login', $login);
if (!empty($num)){
if (preg_match('/[0-9]{9}/', $num)){
$listCommandes = $gestionCommande->listCommandesGreffeBySiren($num);
} elseif(substr($num,0,1)=='G' || substr($num,0,1)=='C'){
$listCommandes = $gestionCommande->listCommandesGreffeByNum($num);
}
} elseif (!empty($login)) {
$listCommandes = $gestionCommande->listCommandesGreffeByLogin($login, $date);
} elseif (!empty($date)) {
$listCommandes = $gestionCommande->listCommandesGreffe($date, $etat, $mode);
}
//Liste des différents états pour les commandes
if ($mode!='-'){
${'status'.$mode} = $gestionCommande->listStatus($mode);
} else {
foreach ($modeSelect as $item){
if($item['value']!='-'){
${'status'.$item['value']} = $gestionCommande->listStatus($item['value']);
}
}
}
//Parcours de la liste des commandes et vérification document existe
if (count($listCommandes)>0) {
for($i=0;$i<count($listCommandes);$i++)
{
//Etat de la commande
$cmdEtatSelect = array();
$cmdEtatSelect[] = array('value'=>0, 'select'=>'', 'affichage'=>'');
$typeCommande = $listCommandes[$i]['typeCommande'];
Zend_Registry::get('firebug')->info($typeCommande);
if (isset(${'status'.$typeCommande})){
foreach(${'status'.$typeCommande} as $item){
$select = '';
if ($item['id']==$listCommandes[$i]['statutCommande']){
$select = ' selected';
}
$cmdEtatSelect[] = array(
'value' => $item['id'],
'affichage' => $item['libStatut'],
'select' => $select,
);
}
}
$listCommandes[$i]['cmdEtatSelect'] = $cmdEtatSelect;
//Lien vers le fichier
$documentLien = '';
switch($type)
{
case 'greffe':
if (preg_match('/^([0-9a-zA-Z]{2}-).*?$/', $listCommandes[$i]['refDocument'], $matches)){
$documentLien = $this->view->url(array(
'controller' => 'pieces',
'action' => 'actes',
'siret' => $listCommandes[$i]['siren'],
));
} elseif (preg_match('/^([0-9]{4}).*?$/', $listCommandes[$i]['refDocument'], $matches)){
$documentLien = $this->view->url(array(
'controller' => 'pieces',
'action' => 'bilans',
'siret' => $listCommandes[$i]['siren'],
));
}
break;
}
$listCommandes[$i]['documentLien'] = $documentLien;
}
}
break; //Fin Gestion Greffes
}
$this->view->assign('commandes', $listCommandes);
$this->renderScript('dashboard/commandes-'.$type.'.phtml');
}
//Affichage des liens vers les différents types de commande
$this->view->assign('typesCommande', $typesCommande);
}
/**
* Modification de l'état d'une commande infogreffe
*/
public function commandesetatchangeAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$etat = $request->getParam('etat');
$idCommande = $request->getParam('idCommande');
require_once 'Scores/GestionCommandes.php';
$commande = new GestionCommande();
echo $commande->changeEtat($idCommande, $etat);
}
/**
* Affichage de la raison sociale à partir du siren
*/
public function rsAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$siren = $request->getParam('siren');
$ws = new WsScores();
$infos = $ws->getIdentite($siren);
if ($infos==false) {
echo 'Erreur';
} else {
echo $infos->Nom;
}
}
/**
* Génération automatique du courrier PDF / ODT
*/
public function courrierAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$numCommande = $request->getParam('commande');
require_once 'GenCourrier/GenCourrier.php';
$courrier = new GenCourrier($numCommande);
$courrier->computeOdt();
}
/**
* Liste les clients
*/
public function clientsAction()
{
$this->view->headScript()->appendFile('/themes/default/scripts/dashboard.js', 'text/javascript');
$ws = new WsScores();
$reponse = $ws->getListeClients();
$listeClients = $reponse->result->item;
$reponse = $ws->getListeDroits();
$wsdroits = $reponse->item;
$this->view->assign('ListeClients', $listeClients);
$this->view->assign('wsdroits', $wsdroits);
}
/**
* Edition ou création d'un nouveau client
*/
public function clientAction()
{
$this->view->headScript()->appendFile('/themes/default/scripts/jquery.checkbox.js', 'text/javascript');
$this->view->headLink()->appendStylesheet('/themes/default/styles/jquery.checkbox.css', 'all');
$request = $this->getRequest();
$idClient = $request->getParam('idClient', false);
$titre = 'CREATION NOUVEAU CLIENT';
$submitValue = 'Créer le client';
if ($idClient!==false){
$ws = new WsScores();
$reponse = $ws->getListeClients($idClient);
$InfosClient = $reponse->result->item[0];
$titre = 'EDITION CLIENT';
$submitValue = 'Modifier le client';
}
$ws = new WsScores();
$reponse = $ws->getListeDroits();
$wsdroits = $reponse->item;
$this->view->assign('idClient', $idClient);
$this->view->assign('InfosClient', $InfosClient);
$this->view->assign('titre', $titre);
$this->view->assign('submitValue', $submitValue);
$this->view->assign('wsdroits', $wsdroits);
}
/**
* Enregistre les informations sur le client
*/
public function clientsaveAction()
{
$request = $this->getRequest();
$infos = $request->getParams();
$ws = new WsScores();
$reponse = $ws->setClient($infos);
if ($reponse->error->errnum==1) {
$this->_forward('client', 'dashboard', null, array('idClient' => $infos['idClient']));
}
$this->view->assign('infos', $request->getParams());
}
}