diff --git a/application/Bootstrap.php b/application/Bootstrap.php
index 55d6fd0..46ccdd1 100644
--- a/application/Bootstrap.php
+++ b/application/Bootstrap.php
@@ -18,21 +18,20 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$view->doctype('HTML5');
$view->headMeta()
- ->appendHttpEquiv('viewport', 'width=device-width, initial-scale=1.0')
+ ->appendName('viewport', 'width=device-width, initial-scale=1.0')
+ ->appendHttpEquiv('X-UA-Compatible', 'IE=edge')
->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
->appendHttpEquiv('Content-Language', 'fr-FR');
$view->headLink()
- ->appendStylesheet('/libs/bootstrap-v3.0.2/css/bootstrap.min.css', 'all')
+ ->appendStylesheet('/libs/bootstrap-v3.0.3/css/bootstrap.min.css', 'all')
->appendStylesheet('/themes/default/css/justified-nav.css', 'all');
$view->headScript()
->appendFile('/libs/html5shiv.js', 'text/javascript', array('conditional' => 'lt IE 9'))
- ->appendFile('/libs/respond.min.js', 'text/javascript', array('conditional' => 'lt IE 9'));
-
- $view->inlineScript()
- ->appendFile('/libs/jquery-2.0.3.min.js', 'text/javascript')
- ->appendFile('/libs/bootstrap-v3.0.2/js/bootstrap.min.js', 'text/javascript');
+ ->appendFile('/libs/respond.min.js', 'text/javascript', array('conditional' => 'lt IE 9'))
+ ->appendFile('/libs/jquery-1.10.2.min.js', 'text/javascript')
+ ->appendFile('/libs/bootstrap-v3.0.3/js/bootstrap.min.js', 'text/javascript');
$view->headTitle()->setSeparator(' - ');
$view->headTitle('Partner');
diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php
new file mode 100644
index 0000000..031ad72
--- /dev/null
+++ b/application/controllers/DashboardController.php
@@ -0,0 +1,59 @@
+_helper->layout()->disableLayout();
+ $this->_helper->viewRenderer->setNoRender(true);
+
+ $commandM = new Application_Model_Command();
+
+
+ $c = Zend_Registry::get('config');
+ $path = realpath($c->profil->path->files).'/export/';
+
+ $file = 'liste-commandes-'.$client.'.csv';
+ $handle = fopen($path . $file, 'w');
+ $header = $commandM->info('cols');
+ fputcsv($handle, $header);
+ $data = $commandM->fetchAll($sql);
+ foreach($users->toArray() as $item) {
+ fputcsv($handle, $item);
+ }
+ fclose($handle);
+
+ $content_type = 'application/csv-tab-delimited-table';
+ $c = Zend_Registry::get('config');
+ $path = realpath($c->profil->path->files).'/export/';
+ //Envoi du fichier sur la sortie standard
+ if ( file_exists($path.$file) ) {
+ header('Content-Transfer-Encoding: none');
+ header('Content-type: ' . $content_type.'');
+ header('Content-Length: ' . filesize($path.$file));
+ header('Content-MD5: ' . base64_encode(md5_file($path.$file)));
+ header('Content-Disposition: filename="' . basename($path.$file) . '"');
+ header('Cache-Control: private, max-age=0, must-revalidate');
+ header('Pragma: public');
+ ini_set('zlib.output_compression', '0');
+ echo file_get_contents($path.$file);
+ } else {
+ echo 'Impossible de charger le fichier.';
+ }
+
+ }
+ //Lister les commandes OK eta = 0
+ else {
+ $commandM = new Application_Model_Command();
+ $sql = $commandM->select()->where('eta = ?',0);
+ $this->view->Commands = $commandM->fetchAll($sql);
+ //Télécharger le rapport
+ //Regénérer le rapport
+ //Télécharger la facture
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/application/controllers/ReportController.php b/application/controllers/ReportController.php
index 0600ec8..012b213 100644
--- a/application/controllers/ReportController.php
+++ b/application/controllers/ReportController.php
@@ -1,12 +1,18 @@
view->inlineScript()
- ->appendFile('/libs/jquery-2.0.3.min.js', 'text/javascript')
- ->appendFile('/libs/bootstrap-v3.0.0/js/bootstrap.min.js', 'text/javascript');
+ $this->view->headLink()
+ ->appendStylesheet('/themes/default/css/justified-nav.css', 'all');
+
+ $c = Zend_Registry::get('config');
+ $year = date('Y');
+ $this->tva = $c->profil->report->tva->{$year};
+ $this->montantht = $c->profil->report->montantht;
+ $this->montant = $this->montantht * (1 + $this->tva / 100);
}
/**
@@ -56,7 +62,7 @@ class ReportController extends Zend_Controller_Action
'siren'=>$response->Siren
));
- $this->view->montant = $c->profil->report->montantht." € HT" . " (".$c->profil->report->montant." € TTC)";
+ $this->view->montant = $this->montantht." € HT" . " (".$this->montant." € TTC)";
//Session
$session->CmdSiren = $response->Siren;
@@ -162,7 +168,7 @@ class ReportController extends Zend_Controller_Action
}
$c = Zend_Registry::get('config');
- $this->view->montant = $c->profil->report->montantht." € HT" . " (".$c->profil->report->montant." € TTC)";
+ $this->view->montant = $this->montantht." € HT" . " (".$this->montant." € TTC)";
if ( !isset($session->CmdID) || empty($session->CmdID) ) {
//Get the report
@@ -246,15 +252,14 @@ class ReportController extends Zend_Controller_Action
$row = $commandM->fetchRow('cmdId="'.$cmdId.'"');
if ($row !== null) {
- $c = Zend_Registry::get('config');
- $this->view->montant = $c->profil->report->montantht." € HT" . " (".$c->profil->report->montant." € TTC)";
+ $this->view->montant = $this->montantht." € HT" . " (".$this->montant." € TTC)";
//Paybox
$paybox = new Paybox_System(false);
$paybox->setUrlPaiement();
$paybox->setEmail($row->email);
$paybox->setReference($cmdId);
- $paybox->setMontant($c->profil->report->montant);
+ $paybox->setMontant($this->montant);
$paybox->setUrlParameters("http://".$request->getHttpHost()."/report/retour");
//$paybox->setUrlParameters();
$paybox->calculateHMAC();
@@ -318,6 +323,8 @@ class ReportController extends Zend_Controller_Action
if ($row !== null) {
//Enregistrement des valeurs de paiement
$data = array(
+ 'mt' => $this->montantht,
+ 'tax' => $this->tva,
'eta' => $params['eta'],
'auto' => $params['auto'],
'type' => $params['type'],
@@ -397,11 +404,19 @@ class ReportController extends Zend_Controller_Action
'controller'=>'report',
'action'=>'pdf',
'id' => $row->cmdId))
- );
+ );
+ //Facture
+ $links[] = array(
+ 'title' => 'Facture',
+ 'desc' => 'Télécharger votre facture',
+ 'url' => $this->view->url(array(
+ 'controller'=>'report',
+ 'action'=>'bill',
+ 'id' => $row->cmdId))
+ );
}
$this->view->links = $links;
-
}
}
}
@@ -453,7 +468,7 @@ class ReportController extends Zend_Controller_Action
if ( $file ) {
if( file_exists($file) && filesize($file)>0 ) {
header('Content-Transfer-Encoding: none');
- header('Content-type: ' . $content_type.'');
+ header('Content-type: application/pdf');
header('Content-Length: ' . filesize($file));
header('Content-MD5: ' . base64_encode(md5_file($file)));
header('Content-Disposition: filename="' . basename($file) . '"');
@@ -469,4 +484,180 @@ class ReportController extends Zend_Controller_Action
}
}
+ /**
+ * Affichage du fichier Pdf généré pour la commande
+ */
+ public function getcmdAction()
+ {
+ $request = $this->getRequest();
+ $cmdId = $request->getParam('id');
+
+ $c = Zend_Registry::get('config');
+ $path = $c->profil->path->data;
+
+ $auth = Zend_Auth::getInstance();
+
+ //If auth => file
+ if ($auth->hasIdentity()
+ //If REF and EMAIL and eta = 0, OK => file et commande moins d'un mois
+
+ ) {
+ $file = $path . DIRECTORY_SEPARATOR . $cmdId . '.pdf';
+ if( file_exists($file) && filesize($file)>0 ) {
+ header('Content-Transfer-Encoding: none');
+ header('Content-type: application/pdf');
+ 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.";
+ }
+ }
+ }
+
+ /**
+ * Create bill and send it as Pdf
+ */
+ public function billAction()
+ {
+ $request = $this->getRequest();
+ $cmdId = $request->getParam('id');
+ $regen = $request->getParam('regen');
+
+ //Selection de la commande
+ $commandM = new Application_Model_Command();
+ $sql = $commandM->select()->where('cmdId = ?',$cmdId);
+ $row = $commandM->fetchRow($sql);
+
+ //Selection de la facture
+ $billM = new Application_Model_ReportBill();
+ $sql = $billM->select()->where('cmdId = ?',$cmdId);
+ $bill = $billM->fetchRow($sql);
+
+ //Verif
+ if ( $row !== null) {
+
+ $c = Zend_Registry::get('config');
+ $path = $c->profil->path->data.'/bill/';
+
+ //Générer la facture
+ if ($bill === null || $bill->file == '' || $regen!==null) {
+
+ //Prepare information in database
+ if ( $bill === null ) {
+ $NumCmd = $billM->insert(array(
+ 'cmdId' => $cmdId,
+ ));
+ } elseif ( $bill !== null && $regen !== null ) {
+ $NumCmd = $bill->id;
+ }
+
+ //Set filename
+ $file = 'bill-'.$cmdId.'-'.$NumCmd.'.pdf';
+
+ $date = new Zend_Date($row->dateInsert, 'yyyy-MM-dd HH:mm:ss');
+
+ //Create PDF
+ //$pdf = new Zend_Pdf();
+ //$pdf->load(APPLICATION_PATH . '/controllers/bill_modele.pdf');
+ $pdf = Zend_Pdf::load(APPLICATION_PATH . '/controllers/bill_modele.pdf');
+
+ $page = $pdf->pages[0];
+ $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
+ $page->setFont($font, 8);
+
+ //Numero de facture
+ $page->drawText('P144.'.$date->toString('yy').'.'.$date->toString('MM').'.'.str_pad($NumCmd, 5, '0', STR_PAD_LEFT), 300, 720, 'UTF-8');
+ //Date
+ $page->drawText($date->toString('dd/MM/yyyy'), 390, 720, 'UTF-8');
+ //Numéro client
+ $page->drawText('P144.'.str_pad($NumCmd, 5, '0', STR_PAD_LEFT), 475, 720, 'UTF-8');
+
+ $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
+ $page->setFont($font, 10);
+ //Prestataire
+ $prestataireL1 = 'Scores & Décisions';
+ $prestataireL2 = '1 rue de Clairefontaine';
+ $prestataireL3 = '78120 Rambouillet';
+ $prestataireL4 = 'Contact : compta@scores-decisions.com';
+ $prestataireL5 = 'R.C.S. : 2008B04241 RCS Versailles';
+ $prestataireL6 = 'N.I.I. : FR84 494967938';
+ $page->drawText($prestataireL1, 60, 640, 'UTF-8');
+ $page->drawText($prestataireL2, 60, 625, 'UTF-8');
+ $page->drawText($prestataireL3, 60, 610, 'UTF-8');
+ $page->drawText($prestataireL4, 60, 595, 'UTF-8');
+ $page->drawText($prestataireL5, 60, 580, 'UTF-8');
+ $page->drawText($prestataireL6, 60, 565, 'UTF-8');
+ //Destinataire
+ $destinataireL1 = strtoupper($row->rs);
+ $destinataireL2 = strtoupper($row->nom . ' ' .$row->prenom);
+ $destinataireL3 = '';
+ $destinataireL4 = strtoupper($row->adresse);
+ $destinataireL5 = strtoupper($row->cp . ' ' . $row->ville);
+ $destinataireL6 = strtoupper($row->pays);
+ $page->drawText($destinataireL1, 300, 640, 'UTF-8');
+ $page->drawText($destinataireL2, 300, 625, 'UTF-8');
+ $page->drawText($destinataireL3, 300, 610, 'UTF-8');
+ $page->drawText($destinataireL4, 300, 595, 'UTF-8');
+ $page->drawText($destinataireL5, 300, 580, 'UTF-8');
+ $page->drawText($destinataireL6, 300, 565, 'UTF-8');
+ //Article
+ $page->drawText($date->toString('dd/MM/yyyy'), 60, 450, 'UTF-8');
+ $page->drawText($row->cmdId, 150, 450, 'UTF-8');
+ $page->drawText("Rapport financier", 250, 450, 'UTF-8');
+ $page->drawText("1", 360, 450, 'UTF-8');
+ $page->drawText(number_format($row->mt, 2).' €', 420, 450, 'UTF-8');
+ $page->drawText(number_format($row->mt, 2).' €', 485, 450, 'UTF-8');
+ //Summary TotalHT TVA MontantTVA TotalTTC NetAPayer
+ $page->drawText(number_format($row->mt,2).' €', 90, 208, 'UTF-8');
+ $page->drawText(number_format($row->tax,2).' €', 190, 208, 'UTF-8');
+
+ $mtTAX = $row->mt * $row->tax/100 ;
+ $mtTTC = $mtNET = $row->mt * ( 1 + $row->tax/100 ) ;
+
+ $page->drawText(number_format($mtTAX,2).' €', 290, 208, 'UTF-8');
+ $page->drawText(number_format($mtTTC,2).' €', 390, 208, 'UTF-8');
+ $page->drawText(number_format($mtNET,2).' €', 490, 208, 'UTF-8');
+
+ //Mode de paiement
+ $page->drawText("Paiement en ligne - Carte bancaire", 100, 134, 'UTF-8');
+ //Date de paiement
+ $page->drawText($date->toString('dd/MM/yyyy HH:mm:ss'), 370, 134, 'UTF-8');
+
+ $pdf->save($path.$file);
+
+ $billM->update(array('file' => $file), 'id='.$NumCmd);
+
+ /**
+ALTER TABLE `command` ADD `mt` FLOAT NOT NULL COMMENT 'Montant Hors taxes' AFTER `cmdId` ,
+ADD `tax` FLOAT NOT NULL COMMENT 'Taux de taxe' AFTER `mt` ;
+ */
+ }
+ //Distribuer la facture
+ else {
+ $file = $bill->file;
+ }
+
+ //Display Bill
+ if( file_exists($path.$file) && filesize($path.$file)>0 ) {
+ header('Content-Transfer-Encoding: none');
+ header('Content-type: application/pdf');
+ header('Content-Length: ' . filesize($path.$file));
+ header('Content-MD5: ' . base64_encode(md5_file($path.$file)));
+ header('Content-Disposition: filename="' . basename($path.$file) . '"');
+ header('Cache-Control: private, max-age=0, must-revalidate');
+ header('Pragma: public');
+ ini_set('zlib.output_compression', '0');
+ echo file_get_contents($path.$file);
+ } else {
+ echo "Erreur lors de l'affichage du fichier.";
+ }
+
+ }
+ }
+
}
\ No newline at end of file
diff --git a/application/controllers/UserController.php b/application/controllers/UserController.php
new file mode 100644
index 0000000..f69f39e
--- /dev/null
+++ b/application/controllers/UserController.php
@@ -0,0 +1,90 @@
+view->headTitle()->append('Connexion');
+ $form = new Application_Form_Login();
+ $this->view->form = $form;
+ $request = $this->getRequest();
+ if ( $request->isPost() ) {
+ $formData = $request->getPost();
+ if ($form->isValid($formData)) {
+ $login = $form->getValue('login');
+ $pass = $form->getValue('pass');
+
+ $auth = Zend_Auth::getInstance();
+ $authAdapter = new Scores_Auth_Adapter_Ws($login, md5($login.'|'.$pass));
+ $result = $auth->authenticate($authAdapter);
+
+ //Auth is valid
+ if ( $result->isValid() ) {
+ //Get previous url if user has been disconnected
+ $url = '';
+ if (Zend_Session::namespaceIsset('login')){
+ $session = new Zend_Session_Namespace('login');
+ if (isset($session->url)) {
+ $url = $session->url;
+ }
+ }
+ if (!empty($url) && $url!='/user/login' && $url!='/user/logout' && $url!='/localauth'){
+ $this->_redirect($url);
+ }
+ $this->_redirect('/');
+ }
+ //Auth error
+ else {
+
+ $this->view->message = '';
+ Zend_Registry::get('firebug')->info($result);
+ foreach ($result->getMessages() as $message) {
+ $this->view->message.= $message."
";
+ }
+ }
+ }
+ }
+ $this->_helper->layout()->disableLayout();
+ }
+
+ /**
+ * Gestion de la déconnexion
+ */
+ public function logoutAction()
+ {
+ Zend_Auth::getInstance()->clearIdentity();
+ $session = new Zend_Session_Namespace('wcheck');
+ $session->unsetAll();
+ $this->_helper->layout()->disableLayout();
+
+ $request = $this->getRequest();
+ $message = $request->getParam('message');
+ $this->view->assign('message', $message);
+
+ $ajax = $request->getParam('ajax', 0);
+ $this->view->assign('ajax', $ajax);
+
+ $refresh = 5;
+
+ $url = 'http://'.$_SERVER['SERVER_NAME'].$this->view->url(array(
+ 'controller' => 'user',
+ 'action' => 'login',
+ ), null, true);
+
+ $this->view->assign('url', $url);
+
+ if (!$ajax) {
+ $this->view->assign('refresh', $refresh);
+ $this->view->headMeta()->appendHttpEquiv('refresh', $refresh.'; url='.$url);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/application/controllers/bill_modele.pdf b/application/controllers/bill_modele.pdf
new file mode 100644
index 0000000..8714ebb
Binary files /dev/null and b/application/controllers/bill_modele.pdf differ
diff --git a/application/models/ReportBill.php b/application/models/ReportBill.php
new file mode 100644
index 0000000..788b613
--- /dev/null
+++ b/application/models/ReportBill.php
@@ -0,0 +1,5 @@
+
-