195 lines
6.9 KiB
PHP
195 lines
6.9 KiB
PHP
<?php
|
|
/**
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to a commercial license.
|
|
* Use, copy, modification or distribution of this source file without written
|
|
* license agreement is strictly forbidden.
|
|
* In order to obtain a license, please contact us: simon@daig.re
|
|
* ...........................................................................
|
|
* INFORMATION SUR LA LICENCE D'UTILISATION
|
|
*
|
|
* L'utilisation de ce fichier source est soumise a une licence commerciale.
|
|
* Toute utilisation, reproduction, modification ou distribution du present
|
|
* fichier source sans contrat de licence ecrit est expressement interdite.
|
|
* Pour obtenir une licence, veuillez nous contacter a l'adresse: simon@daig.re
|
|
*
|
|
* @package La Poste Courrier suivi Tracking
|
|
* @author Agencya
|
|
* @copyright Copyright(c) 2015-2018
|
|
* @license See Readme.md
|
|
* Contact by Email : simon@daig.re
|
|
*/
|
|
|
|
class AdminCsuiviTrackingController extends ModuleAdminController
|
|
{
|
|
/** @var string */
|
|
public $module = 'csuivitracking';
|
|
|
|
/**
|
|
* AdminCsuiviTrackingController constructor.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->context = Context::getContext();
|
|
$this->className = 'CsuiviTrackingModel';
|
|
$this->table = 'csuivi_tracking';
|
|
$this->identifier = 'id_csuivi_tracking';
|
|
$this->addRowAction('delete');
|
|
$this->lang = false;
|
|
$this->bootstrap = true;
|
|
$this->list_no_link = true;
|
|
|
|
parent::__construct();
|
|
|
|
$this->_select = '
|
|
o.`reference`, o.id_carrier,
|
|
country_lang.`name` as `cname`,
|
|
ad.`postcode`,
|
|
CONCAT(c.`firstname`, \' \', c.`lastname`) AS `customer`';
|
|
|
|
$this->_join = '
|
|
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = a.`id_order`)
|
|
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = o.`id_customer`)
|
|
LEFT JOIN `'._DB_PREFIX_.'address` ad ON (ad.`id_address` = o.`id_address_delivery`)
|
|
INNER JOIN `'._DB_PREFIX_.'country` country ON (ad.id_country = country.id_country)
|
|
INNER JOIN `'._DB_PREFIX_.'country_lang` country_lang ON (country.`id_country` = country_lang.`id_country` AND country_lang.`id_lang` = '.(int)$this->context->language->id.')';
|
|
|
|
if (Shop::getContext() === Shop::CONTEXT_SHOP) {
|
|
$this->_where = '
|
|
AND o.id_shop = '.$this->context->shop->id;
|
|
}
|
|
|
|
$this->_orderBy = 'id_order';
|
|
$this->_orderWay = 'DESC';
|
|
|
|
$this->fields_list = array(
|
|
'id_order' => array(
|
|
'title' => $this->l('ID'),
|
|
'class' => 'fixed-width-xs',
|
|
'havingFilter' => true,
|
|
'align' => 'center',
|
|
'type' => 'int',
|
|
'callback' => 'getOrderLink'
|
|
),
|
|
'reference' => array(
|
|
'title' => $this->l('Reference'),
|
|
'class' => 'fixed-width-xs',
|
|
),
|
|
'customer' => array(
|
|
'title' => $this->l('Customer'),
|
|
'havingFilter' => true,
|
|
),
|
|
'postcode' => array(
|
|
'title' => $this->l('Postcode'),
|
|
'class' => 'fixed-width-xs',
|
|
),
|
|
'cname' => array(
|
|
'title' => $this->l('Country'),
|
|
'havingFilter' => true,
|
|
),
|
|
'tracking' => array(
|
|
'title' => $this->l('Tracking N°'),
|
|
'callback' => 'getTrackingLink'
|
|
),
|
|
'status' => array(
|
|
'title' => $this->l('Status'),
|
|
),
|
|
'date' => array(
|
|
'title' => $this->l('Date'),
|
|
'align' => 'text-right',
|
|
'class' => 'fixed-width-sm',
|
|
'type' => 'date',
|
|
)
|
|
);
|
|
|
|
if (Tools::version_compare(_PS_VERSION_, '1.6', '<')) {
|
|
$this->module = new CsuiviTracking();
|
|
|
|
$this->toolbar_btn['refresh'] = array(
|
|
'href' => $this->context->link->getAdminLink(Tools::getValue('controller')).'&ajax=1&action=refresh',
|
|
'desc' => $this->l('Refresh'),
|
|
'class' => 'process-icon-refresh'
|
|
);
|
|
|
|
$this->toolbar_btn['clean'] = array(
|
|
'href' => $this->context->link->getAdminLink(Tools::getValue('controller')).'&ajax=1&action=clean',
|
|
'desc' => $this->l('Clean delivered orders'),
|
|
'class' => 'process-icon-refresh'
|
|
);
|
|
|
|
$this->toolbar_btn['configuration'] = array(
|
|
'href' => $this->context->link->getAdminLink('AdminModules').'&configure=csuivitracking',
|
|
'desc' => $this->l('Configuration'),
|
|
'class' => 'process-icon-cogs'
|
|
);
|
|
}
|
|
}
|
|
|
|
public function initPageHeaderToolbar()
|
|
{
|
|
if (empty($this->display)) {
|
|
$this->page_header_toolbar_btn['refresh'] = array(
|
|
'href' => $this->context->link->getAdminLink(Tools::getValue('controller')).'&ajax=1&action=refresh',
|
|
'desc' => $this->l('Refresh'),
|
|
'icon' => 'process-icon-refresh'
|
|
);
|
|
|
|
$this->page_header_toolbar_btn['clean'] = array(
|
|
'href' => $this->context->link->getAdminLink(Tools::getValue('controller')).'&ajax=1&action=clean',
|
|
'desc' => $this->l('Clean delivered orders'),
|
|
'icon' => 'process-icon-refresh'
|
|
);
|
|
|
|
$this->page_header_toolbar_btn['configuration'] = array(
|
|
'href' => $this->context->link->getAdminLink('AdminModules').'&configure=csuivitracking',
|
|
'desc' => $this->l('Configuration'),
|
|
'icon' => 'process-icon-cogs'
|
|
);
|
|
}
|
|
|
|
parent::initPageHeaderToolbar();
|
|
}
|
|
|
|
public function ajaxProcessRefresh()
|
|
{
|
|
CsuiviTracking_Tools::updateOrdersStatus($this->context->shop->id);
|
|
Tools::redirectAdmin($this->context->link->getAdminLink('AdminCsuiviTracking'));
|
|
}
|
|
|
|
public function ajaxProcessClean()
|
|
{
|
|
Db::getInstance()->execute('
|
|
DELETE FROM `'._DB_PREFIX_.'csuivi_tracking`
|
|
WHERE `delivered` = 1'
|
|
);
|
|
|
|
Tools::redirectAdmin($this->context->link->getAdminLink('AdminCsuiviTracking'));
|
|
}
|
|
|
|
/**
|
|
* @param int $id_order
|
|
* @return string
|
|
*/
|
|
public function getOrderLink($id_order)
|
|
{
|
|
return '<a target="_blank" href="'.$this->context->link->getAdminLink('AdminOrders').'&vieworder&id_order='.$id_order.'">'.$id_order.'</a>';
|
|
}
|
|
|
|
/**
|
|
* @param string $tracking
|
|
* @param array $details
|
|
* @return string
|
|
*/
|
|
public function getTrackingLink($tracking, $details)
|
|
{
|
|
$detail_suivi = new CsuiviTrackingModel((int)$details['id_csuivi_tracking']);
|
|
|
|
if (Validate::isLoadedObject($detail_suivi)) {
|
|
return '<a target="_blank" href="'.$detail_suivi->getTrackingUrl().'">'.$detail_suivi->getTrackingFormatted().'</a>';
|
|
} else {
|
|
return $tracking;
|
|
}
|
|
}
|
|
}
|