partner/application/controllers/ReportController.php
2013-11-08 14:32:04 +00:00

455 lines
12 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class ReportController extends Zend_Controller_Action
{
public function init()
{
//Override
$this->view->inlineScript()
->appendFile('/libs/jquery-2.0.3.min.js', 'text/javascript')
->appendFile('/libs/bootstrap-v3.0.0/js/bootstrap.min.js', 'text/javascript');
}
/**
*
*/
public function indexAction()
{
$this->_helper->layout()->disableLayout();
//Open session to backup the state of the process
$cmdState = 0;
$session = new Zend_Session_Namespace('Cmd');
$session->state = $cmdState;
$request = $this->getRequest();
//Define title
//Control the prestation with the database - inject additionnaly parameters
//Get parameters
$siren = $request->getParam('siren');
$this->view->SirenExiste = false;
if (intval($siren)>100) {
//Vérifier que le SIREN existe en base
require_once 'Scores/WsScores.php';
$c = Zend_Registry::get('config');
$login = $c->profil->report->username;
$password = $c->profil->report->password;
$ws = new WsScores($login, $password);
$response = $ws->getIdentiteLight($siren);
if ($response !== false) {
//Identite
$this->view->Siren = $response->Siren;
$this->view->RaisonSociale = $response->Nom;
$this->view->AdresseL1 = $response->Adresse;
$this->view->AdresseL2 = $response->CP . ' ' . $response->Ville;
$this->view->SirenExiste = true;
$this->view->ButtonUrl = $this->view->url(array(
'controller'=>'report',
'action'=>'cmd',
'siren'=>$response->Siren
));
//Session
$session->CmdSiren = $response->Siren;
$session->CmdRaisonSociale = $response->Nom;
$session->CmdAdresseL1 = $response->Adresse;
$session->CmdAdresseL2 = $response->CP . ' ' . $response->Ville;;
//Nombre
$response = $ws->getLiens($siren);
if ( $response !== false ) {
$this->view->NbLiens = count($response->actionnaires->item)
+ count($response->participations->item)
+ count($response->directions->item);
}
$response = $ws->getAnnoncesNum($siren);
if ( $response !== false ) {
foreach ( $response->item as $nb) {
if ( $nb->type == 'bodacc' ) {
$this->view->NbAnnonces = $nb->num;
break;
}
}
}
$response = $ws->getListeBilans($siren);
if ( $response !== false ) {
$this->view->NbBilans = $response->nbReponses;
}
}
}
}
/**
*
*/
public function cmdAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$siren = $request->getParam('siren');
$url = $this->view->url(array(
'controller' => 'report',
'action' => 'index',
'siren' => $siren,
), null, true);
//Affichage du formulaires
$form = new Application_Form_Command();
if ( $request->isPost() ) {
//Write the state to the session
$cmdState = 2;
$session = new Zend_Session_Namespace('Cmd');
if ( $session->state > $cmdState ) {
$this->redirect($url);
} else {
$session->state = $cmdState;
}
$values = $request->getPost();
$form->populate($values);
$this->view->CmdID = $session->CmdID;
if ( $form->isValid($values) ) {
//Sauvegarde des informations
$commandM = new Application_Model_Command();
try {
$commandM->insert($form->getValues());
//Passage à la page suivante
$url = $this->view->url(array(
'controller' => 'report',
'action' => 'deliver', //paiement
'id' => $form->getValue('cmdId'),
), null, true);
$this->redirect($url);
} catch (Zend_Db_Adapter_Exception $e) {
$this->view->msg = "Impossible de passer la commande.";
}
}
} else {
//Write the state to the session
$cmdState = 1;
$session = new Zend_Session_Namespace('Cmd');
if ( $session->state > $cmdState ) {
$this->redirect($url);
} else {
$session->state = $cmdState;
$this->view->Siren = $session->CmdSiren;
$this->view->RaisonSociale = $session->CmdRaisonSociale;
$this->view->AdresseL1 = $session->CmdAdresseL1;
$this->view->AdresseL2 = $session->CmdAdresseL2;
}
if ( !isset($session->CmdID) || empty($session->CmdID) ) {
//Get the report
if (intval($siren)>100) {
//$report = new Scores_Partner_Report('indiscore3', $siren, 'mricois', 'ju2loh6o');
//$html = $report->getContent();
$html = 'blabla';
if ( $html !== false ) {
$c = Zend_Registry::get('config');
$pathCmd = $c->profil->path->data;
$id = uniqid();
//Write the file (name with commande id)
if ( file_put_contents($pathCmd . DIRECTORY_SEPARATOR . $id.'.html', $html) ) {
$session->CmdID = $this->view->CmdID = $id;
}
}
}
} else {
$this->view->CmdID = $session->CmdID;
}
}
//Test
$session = new Zend_Session_Namespace('Cmd');
$this->view->CmdID = 'test';
$this->view->Siren = $session->CmdSiren;
$this->view->RaisonSociale = $session->CmdRaisonSociale;
$this->view->AdresseL1 = $session->CmdAdresseL1;
$this->view->AdresseL2 = $session->CmdAdresseL2;
$this->view->form = $form;
$this->view->siren = $siren;
}
/**
* Sélection du mode de paiement
*/
public function paiementAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
//Commande ID
$cmdId = $request->getParam('id');
//Write the state to the session
$cmdState = 3;
$session = new Zend_Session_Namespace('Cmd');
if ( $session->state > $cmdState || $session->CmdID != $cmdId ) {
$url = $this->view->url(array(
'controller' => 'report',
'action' => 'index',
'siren' => $session->CmdSiren,
), null, true);
$this->redirect($url);
} else {
$session->state = $cmdState;
}
$this->view->CmdID = $session->CmdID;
//$cmdId = '525ffc4501a4d';
//$this->view->CmdID = $cmdId;
$this->view->Siren = $session->CmdSiren;
$this->view->RaisonSociale = $session->CmdRaisonSociale;
$this->view->AdresseL1 = $session->CmdAdresseL1;
$this->view->AdresseL2 = $session->CmdAdresseL2;
//Lire la bdd
$commandM = new Application_Model_Command();
$row = $commandM->fetchRow('cmdId="'.$cmdId.'"');
if ($row !== null) {
//Paybox : Liste des types de paiements possible
$paybox = new Paybox_System();
$paybox->setUrlPaiement();
$paybox->setEmail($row->email);
$paybox->setReference($cmdId);
$paybox->setMontant(10.00);
$paybox->setUrlParameters();
$paybox->calculateHMAC();
//@todo : Set PBX_EFFECTUE, PBX_REFUSE, PBX_ANNULE, PBX_ATTENTE, PBX_REPONDRE_A
$this->view->PayboxUrl = $paybox->getFormUrl();
$this->view->PayboxValues = $paybox->getFormParameters();
}
}
/**
*
*/
public function retourAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$params = $request->getParams();
/*
* PBX_RETOUR
* mt:M => Montant de la transaction
* eta:E
* id:R => Référence commande (précisée dans PBX_CMD)
* auto:A => numéro d'Autorisation (numéro remis par le centre dautorisation)
* type:P => Type de Paiement retenu (cf. PBX_TYPEPAIEMENT)
* idtrans:S => Numéro de TranSaction Paybox
* sign:K => Signature sur les variables de l'URL. Format : url-encodé (toujours en dernier)
*/
$verify = new Paybox_Response();
$verify->setData($params);
if ( $verify->checkData() === false ) {
$error = $verify->getError();
$this->view->PaiementError = $error->label;
} else {
$cmdState = 4;
$session = new Zend_Session_Namespace('Cmd');
if ( $session->state > $cmdState || $session->CmdID != $cmdId ) {
$url = $this->view->url(array(
'controller' => 'report',
'action' => 'index',
'siren' => $session->CmdSiren,
), null, true);
$this->redirect($url);
} else {
$session->state = $cmdState;
}
$cmdId = $request->getParam('id');
//Vérification que la commande existe
$commandM = new Application_Model_Command();
$row = $commandM->fetchRow('cmdId="'.$cmdId.'"');
if ($row !== null) {
//Enregistrement des valeurs de paiement
$data = array(
'eta' => $params['eta'],
'auto' => $params['auto'],
'type' => $params['type'],
'idtrans' => $params['idtrans'],
);
$commandM->update($data, 'id='.$row->id);
//Génération de l'url de livraison
$deliveryUrl = $this->view->url(array(
'controller'=>'report',
'action'=>'deliver',
'id' => $row->cmdId
));
$this->view->deliveryUrl = $deliveryUrl;
}
}
}
public function deliverAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$c = Zend_Registry::get('config');
$pathCmd = $c->profil->path->data;
//Commande ID
$cmdId = $request->getParam('id');
$cmdState = 5;
$session = new Zend_Session_Namespace('Cmd');
if ( $session->state > $cmdState || $session->CmdID != $cmdId ) {
$url = $this->view->url(array(
'controller' => 'report',
'action' => 'index',
'siren' => $session->CmdSiren,
), null, true);
$this->redirect($url);
} else {
$session->state = $cmdState;
}
//Est ce que la commande existe
$commandM = new Application_Model_Command();
$where = $commandM->select()->where('cmdId=?', $cmdId);
$row = $commandM->fetchRow($where);
if ( $row!==null ) {
$infos = new stdClass();
$infos->NumCommande = $row->cmdId;
$date = new Zend_Date($row->dateInsert);
$infos->DateCommande = $date->toString('dd/MM/yyyy HH:mm:ss');
$infos->RaisonSociale = $row->rs;
$infos->NomPrenom = $row->nom . ' ' . $row->prenom;
$infos->Adresse = $row->adresse;
$infos->CpVille = $row->cp . ' ' . $row->ville;
$infos->Tel = $row->tel;
$infos->Mob = $row->mobile;
$this->view->Infos = $infos;
if ( file_exists($pathCmd . DIRECTORY_SEPARATOR . $row->cmdId . '.html') ) {
//Define links to get the HTML and/or PDF
$links = array(
0 => array(
'title' => 'Fichier PDF',
'desc' => 'Télécharger le bilan financier',
'url' => $this->view->url(array(
'controller'=>'report',
'action'=>'pdf',
'id' => $row->cmdId
))
),
);
}
}
}
/**
* Display in blank page the html
*/
public function htmlAction()
{
$this->_helper->layout()->disableLayout();
}
/**
* Distribute pdf file
*/
public function pdfAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$file = false;
//Commande ID
$cmdId = $request->getParam('id');
//Est ce que la commande existe
$commandM = new Application_Model_Command();
$where = $commandM->select()->where('cmdId=?', $cmdId);
$row = $commandM->fetchRow($where);
if ( $row !== null ) {
//Copy html from command directory to temporary storage
$c = Zend_Registry::get('config');
$source = $c->profil->path->data . DIRECTORY_SEPARATOR . $row->cmdId . '.html';
$dest = $c->profil->path->pages . DIRECTORY_SEPARATOR . $row->cmdId . '.html';
if ( copy($source, $dest) ) {
$wkthml = new Scores_Wkhtml_Pdf();
$file = $wkhtml->exec($dest);
}
}
//Distribute it to the output
if ( $file ) {
if( file_exists($file) && filesize($file)>0 ) {
header('Content-Transfer-Encoding: none');
header('Content-type: ' . $content_type.'');
header('Content-Length: ' . filesize($file));
header('Content-MD5: ' . base64_encode(md5_file($file)));
header('Content-Disposition: filename="' . basename($file) . '"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression', '0');
echo file_get_contents($file);
} else {
echo "Erreur lors de l'affichage du fichier.";
}
} else {
echo "Erreur lors de la génération du fichier.";
}
}
}