diff --git a/application/modules/achatclient/controllers/IndexController.php b/application/modules/achatclient/controllers/IndexController.php index 1f3a9335c..ac8b2ff46 100644 --- a/application/modules/achatclient/controllers/IndexController.php +++ b/application/modules/achatclient/controllers/IndexController.php @@ -11,13 +11,17 @@ class Achatclient_IndexController extends Zend_Controller_Action protected $logger; protected $tranches=array( - '200' => array('montant' => 2000,'montantht' => 1667, 'tva' => 333, ), - '500' => array('montant' => 5000,'montantht' => 4167, 'tva' => 833, ), - '1000' => array('montant' => 10000,'montantht' => 8333, 'tva' => 1667, ), + '195' => array( + '200' => array('montant' => 2000,'montantht' => 1667, 'tva' => 333, ), + '500' => array('montant' => 5000,'montantht' => 4167, 'tva' => 833, ), + '1000' => array('montant' => 10000,'montantht' => 8333, 'tva' => 1667, ), + ), ); protected $maxcredit=2000; + protected $libdroits = 'searchent'; + public function init() { if (Zend_Registry::isRegistered('logger')) { @@ -26,7 +30,7 @@ class Achatclient_IndexController extends Zend_Controller_Action $autoloader = Zend_Loader_Autoloader::getInstance(); // --- Theme $this->theme = Zend_Registry::get('theme'); - $request = $this->getRequest(); + $this->view->title='Votre compte crédits en ligne'; require_once 'Scores/WsScores.php'; } @@ -35,40 +39,102 @@ class Achatclient_IndexController extends Zend_Controller_Action */ public function indexAction() { + //Validation des droits $user = new Scores_Utilisateur(); - $ok=$user->checkperm('searchent'); + $ok=$user->checkperm($this->libdroits); if(!$ok){ - $this->redirect('/'); + $this->error('index','Fonction indisponible'); } $ws = new WsScores(); $customer_credit = $ws->getCredit(); + $infos=array('user' => $user,'wscredit' => $customer_credit,'tranches' => $this->tranches); if(intval($customer_credit)>$this->maxcredit){ $this->view->msg='Vous détenez déjà le plafond de crédits autorisé.'; + return; } - $infos=array('user' => $user,'wscredit' => $customer_credit); - $this->view->infos=$infos; - var_dump($infos);die; - $this->logger->info(print_r($infos,1)); - if ($infos === false) { + $this->logger->info(print_r($user,1)); + if ($customer_credit === false and false) { + $this->error('index','Compte indisponible'); $this->forward('soap', 'error'); } - //Paybox - Zend_Loader::loadClass('Paybox_System'); - $paybox = new \Paybox\System(false); - $paybox->setUrlPaiement(); - $paybox->setEmail($row->email); - $paybox->setReference($cmdId); - $paybox->setMontant($this->montant); - $paybox->setUrlRepondreA("http://".$request->getHttpHost()."/report/checkpmt"); - $paybox->setUrlParameters("http://".$request->getHttpHost()."/report/retour"); - $paybox->calculateHMAC(); + //Récupération des Parametres + $infos=array('user' => $user,'wscredit' => intval($customer_credit),'tranches' => $this->tranches[$user->getIdClient()]); + //var_dump($infos);die; + $this->view->infos=$infos; + $this->view->submitValue='Commander'; + } + public function paiementAction() + { + //Validation + $request = $this->getRequest(''); + $user = new Scores_Utilisateur(); + $ok=$user->checkperm($this->libdroits); + if(!$ok){ + $this->error('paiement', __LINE__); + } + $nb_credit=$request->getParam('nb_credit'); + if(intval($nb_credit)==0){ + $this->error('paiement','Vous devez définir le nombre de crédits'); + } + $idClient=$user->getIdClient(); + if(intval($idClient)==0){ + $this->error('paiement', __LINE__); + } + if(!isset($this->tranches[$idClient]) || !isset($this->tranches[$idClient][$nb_credit])){ + $this->error('paiement', __LINE__); + } + //Parametrage + + $pbparam=array(); + $pbparams['cmdId']=implode('#',array($user->identity->id,time())); + $pbparams['email']=$user->identity->email; + $pbparams['montant']=$this->tranches[$idClient][$nb_credit]['montant']/100; + $pbparams['montantht']=$this->tranches[$idClient][$nb_credit]['montantht']/100; + $pbparams['tva']=$this->tranches[$idClient][$nb_credit]['tva']/100; + $ws = new WsScores(); + //$customer_credit = $ws->addCredit(); + $insdata=array( + 'idClient' =>$user->identity->idClient, + 'idCmd' => $pbparams['cmdId'], + 'login' => $user->identity->username, + 'nbCredit' => $nb_credit, + 'amount' => $this->tranches[$idClient][$nb_credit]['montant'], + 'amount_ht' => $this->tranches[$idClient][$nb_credit]['montantht'], + 'amount_tva' => $this->tranches[$idClient][$nb_credit]['tva'], + 'currency' => 'EUR', + 'valid' => 0, + 'date_sent' => Date('Y-m-d H:i:s'), + 'date_received' => null, + 'paybox_answer' => json_encode(array('user' => $user)), + 'comment' => 'Beforecall', + ); + /*@todo + $ws = new WsScores(); + $customer_credit = $ws->addCredit($insdata); + */ + //Paybox + Zend_Loader::loadClass('Paybox_Config'); + Zend_Loader::loadClass('Paybox_System'); + $paybox = new Paybox_System(true); + $paybox->setUrlPaiement(); + $paybox->setEmail($pbparams['email']); + $paybox->setReference($pbparams['cmdId']); + $paybox->setMontant($pbparams['montant']); + //echo "http://".$request->getHttpHost()."/achatclient/pbanswer";die; + //$paybox->setUrlRepondreA("http://".$request->getHttpHost()."/achatclient/checkpmt"); + $paybox->setUrlParameters("http://".$request->getHttpHost()."/achatclient/pbanswer"); + $paybox->calculateHMAC(); + //$_POST=$paybox->getFormParameters(); + //$this->redirect($paybox->getFormUrl()); + $this->view->pbparams = $pbparams; $this->view->PayboxUrl = $paybox->getFormUrl(); $this->view->PayboxValues = $paybox->getFormParameters(); - //$pb=new Paybox_System('test'); - //var_dump($pb); - } + } + public function pbanswer(){ + echo 'thanks';die; + } /** * Sélection du mode de paiement */ @@ -130,6 +196,21 @@ class Achatclient_IndexController extends Zend_Controller_Action } } + public function footerAction(){ + + } + + private function error($ligne=0,$message=""){ + switch($ligne){ + case "index": + case "paiement": + $this->view->msg=$message; + throw new Exception($message); + break; + default: + echo $ligne.' : '.$message;die; + } + } } ?> diff --git a/application/modules/achatclient/views/default/scripts/index/index.phtml b/application/modules/achatclient/views/default/scripts/index/index.phtml index 2b1035556..7023d1c63 100644 --- a/application/modules/achatclient/views/default/scripts/index/index.phtml +++ b/application/modules/achatclient/views/default/scripts/index/index.phtml @@ -1,30 +1,37 @@ +
+Le compte =isset($this->infos['user']->identity->username)?$this->infos['user']->identity->username:""?> détient actuellement =intval($this->infos['wscredit'])?> crédits.
+