Current File : /home/karenpetzb/application/modules/backoffice/controllers/CommandController.php |
<?php
class Backoffice_CommandController extends Modules_Backoffice_Controllers_MainController
{
function init()
{
$this->view->title = "Administration";
$this->view->currentMenu = "Command";
$this->isConnectedWithRole('isCommand');
}
function indexAction()
{
$this->_forward('/listcommand');
}
function searchAction()
{
try {
$this->view->titlePage = "Rechercher une commande";
$this->view->messageSuccess = "";
$this->view->messageError = "";
$startSearch = false;
$isCheckedValidating = false;
$searchValue = "";
if ($this->_request->isPost()) {
$post = $this->_request->getPost();
$filter = new Zend_Filter();
$filter ->addFilter(new Zend_Filter_StripTags())
->addFilter(new Zend_Filter_StringTrim());
$searchValue = $filter->filter($post['searchValue']);
if (isset($post['searchType'])) {
$isCheckedValidating = true;
}
$startSearch = true;
}
//Gestion des tris
$titlePage = "";
$listcommand = array();
if ($startSearch) {
$adminNamespace = $this->getSession();
$adminNamespace->cmdSearchValue = $searchValue;
$adminNamespace->cmdSearchValidating = $isCheckedValidating;
//Appel model pour listing
$command = new Command();
$titlePage .= " : ".$searchValue;
$listcommand = $command->findCommandsByMultiSearch($isCheckedValidating, $searchValue);
}
$this->view->titlePage .= $titlePage;
$this->view->listcommand = $listcommand;
$this->view->searchType = $isCheckedValidating;
$this->view->searchValue = $searchValue;
} catch (Zend_Exception $e) { $this->errorHandler($e); $this->view->messageError = $e->getMessage(); }
}
function listAction()
{
$this->view->titlePage = "Gestion des commandes";
$adminNamespace = $this->getSession();
//Gestion des tris
$table = 'STATUT';
$tri = 'ASC';
if ($this->_request->getParam('col'))
{
$adminNamespace->triCmdCol = $this->_request->getParam('col');
($adminNamespace->triCmdSens == 'ASC') ? $adminNamespace->triCmdSens = 'DESC' : $adminNamespace->triCmdSens = 'ASC';
}
if (isset($adminNamespace->triCmdCol)) {
$table = $adminNamespace->triCmdCol;
$tri = $adminNamespace->triCmdSens;
}
//Appel model pour listing
$command = new Command();
$select = $command->select()->where('STATUT <> 0 AND isARCHIVE = 1')->order($table.' '.$tri);
$this->view->listcommand = $command->fetchAll($select);
}
function listcommandAction()
{
$this->view->titlePage = "Gestion des commandes";
$adminNamespace = $this->getSession();
//Gestion des tris
$table = 'STATUT';
$tri = 'ASC';
if ($this->_request->getParam('col'))
{
$adminNamespace->triCmdCol = $this->_request->getParam('col');
($adminNamespace->triCmdSens == 'ASC') ? $adminNamespace->triCmdSens = 'DESC' : $adminNamespace->triCmdSens = 'ASC';
}
if (isset($adminNamespace->triCmdCol)) {
$table = $adminNamespace->triCmdCol;
$tri = $adminNamespace->triCmdSens;
}
//Appel model pour listing
$command = new Command();
$select = $command->select()->where('isARCHIVE = 1 AND STATUT IN (1, 2, 3, 4)')->order($table.' '.$tri);
$this->view->listcommand = $command->fetchAll($select);
}
function listdevisAction()
{
$this->view->titlePage = "Gestion des devis";
$adminNamespace = $this->getSession();
//Gestion des tris
$table = 'STATUT';
$tri = 'ASC';
if ($this->_request->getParam('col'))
{
$adminNamespace->triCmdCol = $this->_request->getParam('col');
($adminNamespace->triCmdSens == 'ASC') ? $adminNamespace->triCmdSens = 'DESC' : $adminNamespace->triCmdSens = 'ASC';
}
if (isset($adminNamespace->triCmdCol)) {
$table = $adminNamespace->triCmdCol;
$tri = $adminNamespace->triCmdSens;
}
//Appel model pour listing
$command = new Command();
$select = $command->select()->where('isARCHIVE = 1 AND STATUT IN (10, 11)')->order($table.' '.$tri);
$this->view->listcommand = $command->fetchAll($select);
}
//Same as UserController, module default
private function computeFactureTVA($facture, $paysLivraison) {
$fact = new Facture();
$fact->computeFactureTVA($facture, $paysLivraison);
return $facture;
}
function editAction() {
try {
$this->view->messageSuccess = "";
$this->view->messageError = "";
$command = new Command();
if($this->getRequest()->isPost()) {
$id = (int)$this->_request->getPost('idcmd');
$statut = (int)$this->_request->getPost('statut');
$delivery_trackinglink = $this->_request->getPost('delivery_trackinglink');
$delivery_trackingnumber = $this->_request->getPost('delivery_trackingnumber');
if ($id > 0 && $statut>0) {
try {
if ($statut == 3 || $statut == 11) {
$date = new Zend_Date();
$data = array ( 'STATUT' => $statut, 'DATEEND' => $date->toString('YYYY-MM-dd HH:mm:ss') );
} else {
$data = array ( 'STATUT' => $statut, 'DATEEND' => '0000-00-00 00:00:00');
}
if (isset($delivery_trackinglink) && !empty($delivery_trackinglink) &&
isset($delivery_trackingnumber) && !empty($delivery_trackingnumber)) {
$data['DELIVERY_TRACKINGLINK'] = $delivery_trackinglink;
$data['DELIVERY_TRACKINGNUMBER'] = $delivery_trackingnumber;
}
$command->update($data, 'ID = '.$id);
$this->view->messageSuccess = "Le statut a �t� modifi�";
$this->log("Le statut a �t� modifi� : ".$id,'info');
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
$this->view->messageError = $e->getMessage();
}
}
}
if ($this->getRequest()->getParam('id') && (int)$this->getRequest()->getParam('id')>0) {
$id = (int)$this->getRequest()->getParam('id');
}
$isExist = $command->fetchRow("ID = ".$id);
if ($isExist) {
$myCommand = $command->getCommandAsFacture($id);
$this->view->facture = $myCommand;
$titlePage = "Modifier une commande";
switch ($myCommand['STATUT']) {
case 10 :
$titlePage = "Modifier un devis";
break;
case 11 :
$titlePage = "Modifier un devis";
break;
}
$this->view->titlePage = $titlePage;
}
} catch (Zend_Exception $e) { $this->log($e->getMessage(), 'err'); }
}
function delAction() {
$this->view->messageSuccess = "";
$this->view->messageError = "";
if($this->_request->getParam('id')) {
$id = (int)$this->_request->getParam('id');
if ($id > 0) {
try {
$command = new Command();
$commandProduct = new CommandProduct();
$commandProduct->delete('IDCOMMAND = '.$id);
$command->delete('ID = '.$id);
$this->view->messageSuccess = "La commande a �t� supprim�e ";
$this->log("La commande a �t� supprim�e",'info');
$adminNamespace = $this->getSession();
if (isset($adminNamespace->cmdSearchValue) && isset($adminNamespace->cmdSearchValidating)) {
$isCheckedValidating = $adminNamespace->cmdSearchValidating;
$searchValue = $adminNamespace->cmdSearchValue;
//Gestion des tris
$listcommand = array();
//Appel model pour listing
$titlePage = "Rechercher une commande : ".$searchValue;
$listcommand = $command->findCommandsByMultiSearch($isCheckedValidating, $searchValue);
$this->view->titlePage .= $titlePage;
$this->view->listcommand = $listcommand;
$this->view->searchType = $isCheckedValidating;
$this->view->searchValue = $searchValue;
}
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
$this->view->messageError = $e->getMessage();
}
}
}
$this->render('search');
}
function ajaxdelcommandAction() {
if($this->_request->getParam('id')) {
$id = (int)$this->_request->getParam('id');
if ($id > 0) {
try {
$command = new Command();
$commandProduct = new CommandProduct();
$commandProduct->delete('IDCOMMAND = '.$id);
$command->delete('ID = '.$id);
$this->view->messageSuccess = "SUCCESS";
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
$this->view->messageError = "ERROR";
}
}
}
$layout = Zend_Layout::getMvcInstance();
$layout->disableLayout();
$this->render('ajaxmessage');
}
function delcommandAction() {
$this->view->messageSuccess = "";
$this->view->messageError = "";
if($this->_request->getParam('id')) {
$id = (int)$this->_request->getParam('id');
if ($id > 0) {
try {
$command = new Command();
$commandProduct = new CommandProduct();
$commandProduct->delete('IDCOMMAND = '.$id);
$command->delete('ID = '.$id);
$this->view->messageSuccess = "La commande a �t� supprim�e ";
$this->log("La commande a �t� supprim�e",'info');
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
$this->view->messageError = $e->getMessage();
}
}
}
$this->_forward('/listcommand');
}
function deldevisAction() {
$this->view->messageSuccess = "";
$this->view->messageError = "";
if($this->_request->getParam('id')) {
$id = (int)$this->_request->getParam('id');
if ($id > 0) {
try {
$command = new Command();
$commandProduct = new CommandProduct();
$commandProduct->delete('IDCOMMAND = '.$id);
$command->delete('ID = '.$id);
$this->view->messageSuccess = "Le devis a �t� supprim� ";
$this->log("Le devis a �t� supprim�",'info');
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
$this->view->messageError = $e->getMessage();
}
}
}
$this->_forward('/listdevis');
}
function archiveAction() {
if($this->getRequest()->isPost()) {
$checkBoxValues = $this->_request->getPost('checkBoxValues');
$checkBoxValues = substr($checkBoxValues, 0, -1);
try {
if (!empty($checkBoxValues)) {
$command = new Command();
$data = array ( 'isARCHIVE' => 0);
$command->update($data, 'ID in ('.$checkBoxValues.')');
$this->log("Les commandes ont �t� archiv�es "+$checkBoxValues,'info');
}
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
}
}
$this->_forward('/listcommand');
}
function archivecommandAction() {
if($this->getRequest()->isPost()) {
$checkBoxValues = $this->_request->getPost('checkBoxValues');
$checkBoxValues = substr($checkBoxValues, 0, -1);
try {
if (!empty($checkBoxValues)) {
$command = new Command();
$data = array ( 'isARCHIVE' => 0);
$command->update($data, 'ID in ('.$checkBoxValues.')');
$this->log("Les commandes ont �t� archiv�es "+$checkBoxValues,'info');
}
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
}
}
$this->_forward('/listcommand');
}
function archivedevisAction() {
if($this->getRequest()->isPost()) {
$checkBoxValues = $this->_request->getPost('checkBoxValues');
$checkBoxValues = substr($checkBoxValues, 0, -1);
try {
if (!empty($checkBoxValues)) {
$command = new Command();
$data = array ( 'isARCHIVE' => 0);
$command->update($data, 'ID in ('.$checkBoxValues.')');
$this->log("Les devis ont �t� archiv�es "+$checkBoxValues,'info');
}
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
}
}
$this->_forward('/listdevis');
}
function deliverymailAction() {
$id = 0;
if ($this->getRequest()->getParam('id') && (int)$this->getRequest()->getParam('id')>0) {
$id = (int)$this->getRequest()->getParam('id');
}
if ($id > 0) {
$command = new Command();
$isExist = $command->fetchRow("ID = ".$id);
if ($isExist) {
$facture = $command->getCommandAsFacture($id);
$this->view->facture =$facture;
if (isset($facture['DELIVERY_TRACKINGLINK']) && !empty($facture['DELIVERY_TRACKINGLINK']) &&
isset($facture['DELIVERY_TRACKINGNUMBER']) && !empty($facture['DELIVERY_TRACKINGNUMBER'])) {
try {
$view = new Zend_View();
$view->addScriptPath('../application/modules/backoffice/views/scripts/command/');
$view->assign("facture",$facture);
$body = $view->render("facture_deliverytrack.phtml");
$from = $this->serviceClient_Mail;
$objet = "Votre commande : ".$facture['REFERENCE'];
$to = $facture['USER_EMAIL'];
$mail = new Zend_Mail();
$mail->setBodyHtml($body);
$mail->setFrom($from, $this->siteName);
$mail->addTo($to);
$mail->setSubject($objet);
$mail->send();
$this->view->messageSuccess = "L'email de suivi de livraison a �t� envoy� a : ".$to;
$this->log("L'email de suivi de livraison a �t� envoy� a : ".$to,'info');
}
catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
}
} else {
$this->view->messageError = "Vous devez valider l'ajout du lien de suivi de livraison";
}
}
}
$this->view->titlePage = "Modifier une commande";
$this->render("edit");
}
function traitementmailAction() {
$id = 0;
if ($this->getRequest()->getParam('id') && (int)$this->getRequest()->getParam('id')>0) {
$id = (int)$this->getRequest()->getParam('id');
}
if ($id > 0) {
$command = new Command();
$isExist = $command->fetchRow("ID = ".$id);
if ($isExist) {
$facture = $command->getCommandAsFacture($id);
$this->view->facture =$facture;
try {
$view = new Zend_View();
$view->addScriptPath('../application/modules/backoffice/views/scripts/command/');
$view->assign("facture",$facture);
$body = $view->render("facture_traitementinprogress.phtml");
$from = $this->serviceClient_Mail;
$objet = "Votre commande : ".$facture['REFERENCE'];
$to = $facture['USER_EMAIL'];
$mail = new Zend_Mail();
$mail->setBodyHtml($body);
$mail->setFrom($from, $this->siteName);
$mail->addTo($to);
$mail->setSubject($objet);
$mail->send();
$this->view->messageSuccess = "L'email de la commande en cours de traitement a �t� envoy� a : ".$to;
$this->log("L'email de la commande en cours de traitement a �t� envoy� a : ".$to,'info');
}
catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
}
}
}
$this->view->titlePage = "Modifier une commande";
$this->render("edit");
}
}
?>