l('Configurations mises à jour'));
} elseif(Tools::isSubmit('submitProductSaleCache')) {
$fileName = 'cron_sale_cache.php';
$output = shell_exec("ps -ax | grep $fileName | wc -l");
$hour = (int) date('H');
$min = (int) date('i');
if($output > 2){
HelperFormBootstrap::displayErrors($this->l('Association automatique en cours, réessayez plus tard'));
}elseif ($hour%3 == 0 && $min <= 20 && $min >= 10 ){
HelperFormBootstrap::displayErrors($this->l('Association automatique en cours, réessayez plus tard'));
} else {
$min_id_product = Db::getInstance()->getValue('
SELECT MIN(`id_product`) FROM `'._DB_PREFIX_.'product` WHERE `date_add` > DATE_SUB(NOW(), INTERVAL 10 DAY)
');
if ($min_id_product) {
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` >= '.$min_id_product.'
');
Db::getInstance()->ExecuteS('
INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
SELECT p.id_product, IFNULL(
(
SELECT s.id_sale
FROM `'._DB_PREFIX_.'privatesale_category` s
WHERE s.`id_category` = p.`id_category_default`
LIMIT 1)
, 0
)
FROM `'._DB_PREFIX_.'product` p
WHERE p.`id_product` >= '.$min_id_product.'
)
');
// LOG ACTION
Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'ant_log`
VALUES (
DEFAULT,
'.(int) $cookie->id_employee.',
"'.pSQL('Association manuelle product_ps_cache via Configuration').'",
NOW()
)
');
HelperFormBootstrap::displaySuccess($this->l('Produits associés aux ventes depuis le produit #').$min_id_product);
} else {
HelperFormBootstrap::displayWarning($this->l('Pas de produit ajouté depuis 10 jours'));
}
}
} elseif(Tools::isSubmit('submitCategorySaleCache')) {
$id_sale = Tools::getValue('id_sale');
if($id_sale) {
$sale = new Sale((int)$id_sale);
$sale->buildCategoryCache();
// LOG ACTION
Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'ant_log`
VALUES (
DEFAULT,
'.(int) $cookie->id_employee.',
"'.pSQL('Association manuelle categories via Configuration, sale: '.$id_sale).'",
NOW()
)
');
HelperFormBootstrap::displaySuccess($this->l('Categories associés à la vente ').$id_sale);
} else {
HelperFormBootstrap::displayErrors($this->l('Veuillez choisir une vente'));
}
} elseif(Tools::isSubmit('submitUpdateLoyaltyOrders') && $cookie->id_employee == 1) {
$nb_credits = $this->updateLoyaltyOrders();
HelperFormBootstrap::displaySuccess($this->l('Credit fidélité mis à jour : ').$nb_credits);
} elseif(Tools::isSubmit('submitCleanMenuCache') && $cookie->id_employee == 1) {
$this->cleanMenuCache();
HelperFormBootstrap::displaySuccess($this->l('Cache du menu regénéré'));
} elseif(
(Tools::isSubmit('submitUpdateCacheSale') || Tools::isSubmit('submitShowProductCacheSale'))
&& $cookie->id_employee == 1)
{
$id_category = Tools::getValue('id_category');
if($id_category) {
$products_ids = array();
foreach(Db::getInstance()->ExecuteS('
SELECT p.id_product
FROM `ps_product` p
WHERE p.`id_category_default` = '.$id_category.'
') as $row) {
$products_ids[(int)$row['id_product']] = (int)$row['id_product'];
}
if(count($products_ids)>0) {
if(Tools::isSubmit('submitShowProductCacheSale')) {
// show product
$result = implode(', ',$products_ids);
HelperFormBootstrap::displaySuccess($this->l('Produits concernés ').'('.count($products_ids).') :
'.wordwrap($result, 100, "
"));
} elseif(Tools::isSubmit('submitUpdateCacheSale')) {
// update product_ps_cache
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` IN ('.implode(',',$products_ids).')
');
Db::getInstance()->ExecuteS('
INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
SELECT p.id_product, IFNULL(
(
SELECT s.id_sale
FROM `'._DB_PREFIX_.'privatesale_category` s
WHERE s.`id_category` = p.`id_category_default`
LIMIT 1)
, 0
)
FROM `ps_product` p
WHERE p.`id_category_default` = '.$id_category.'
)
');
HelperFormBootstrap::displaySuccess($this->l('Association vente produit mise à jour: #').$id_category);
}
} else{
HelperFormBootstrap::displayErrors($this->l('Pas de produits trouvés dans cette catégorie :#').$id_category);
}
} else {
HelperFormBootstrap::displayErrors($this->l('Veuillez choisir une categorie'));
}
} elseif(Tools::isSubmit('submitExportDiscount')){
ini_set('memory_limit', '4G');
$from = Tools::getValue('date_from');
$to = Tools::getValue('date_to');
$results = DB::getInstance()->ExecuteS('
SELECT dh.`id_customer`, dh.`date_add` as `date_generate`,od.`id_order`, dh.`code`, od.`value`, o.`total_paid_real`,o.`date_add` as `date_order`
FROM `'._DB_PREFIX_.'ant_discount_history` dh
LEFT JOIN `'._DB_PREFIX_.'order_discount` od ON (od.`id_discount` = dh.`id_discount`)
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = od.`id_order`)
WHERE 1
'.($from && !empty($from)?' AND dh.`date_add` > "'.$from.' 00:00:00"':'').'
'.($to && !empty($to)?' AND dh.`date_add` < "'.$to.' 00:00:00"':'').'
');
if($results) {
$row_definition = array(
'id_customer' => 'Client ID',
'id_order' => 'Commande ID',
'code' => 'Bon de réduction',
'value' => 'Valeur Bon',
'total_paid_real' => 'Total Commande',
'date_generate' => 'Date création du bon',
'date_order' => 'Date Commande',
);
header("Content-Type: text/csv; charset=UTF-8");
header("Content-Disposition: attachment;filename=export-".date('dmYHi').".csv;");
$this->exportCsv($results, $row_definition);
die();
} else {
HelperFormBootstrap::displayWarning($this->l('Aucun résultat trouvé'));
}
} elseif (Tools::isSubmit('submitExportLoyalty')){
if(!Tools::getValue('date_from') && !Tools::getValue('date_to')) {
HelperFormBootstrap::displayWarning($this->l('Vous devez choisir une période !'));
} else {
$from = Tools::getValue('date_from');
$to = Tools::getValue('date_to');
$results = DB::getInstance()->ExecuteS('
SELECT l.`id_customer`,
(
SELECT c.`iso_code`
FROM `'._DB_PREFIX_.'country` c
LEFT JOIN `'._DB_PREFIX_.'address` a ON (a.`id_country` = c.`id_country`)
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_address_invoice` = a.`id_address`)
WHERE o.`id_order` = l.`id_order`
) as `nationality`,
CASE
WHEN
l.`id_discount` = 0 OR
l.`id_discount` IS NULL
THEN
"Non transforme"
ELSE
l.id_discount
END as `discount`,
l.`discount_value` as `credit`,
DATE_FORMAT(l.`date_add`,"%d/%m/%Y") as `date_generated`,
IFNULL(
(
SELECT DATE_FORMAT(o2.`date_add`,"%d/%m/%Y")
FROM `'._DB_PREFIX_.'orders` o2
LEFT JOIN `'._DB_PREFIX_.'order_discount` od ON (od.`id_order` = o2.`id_order`)
WHERE od.`id_discount` = l.`id_discount`
AND DATE(o2.`date_add`) >= "'.$from.'"
AND DATE(o2.`date_add`) <= "'.$to.'"
)
, "Non utilise dans cette periode") as `date_used_in_period`,
IFNULL(
(
SELECT DATE_FORMAT(o3.`date_add`,"%d/%m/%Y")
FROM `'._DB_PREFIX_.'orders` o3
LEFT JOIN `'._DB_PREFIX_.'order_discount` od ON (od.`id_order` = o3.`id_order`)
WHERE od.`id_discount` = l.`id_discount`
)
, "Non utilise") as `date_used`
FROM `'._DB_PREFIX_.'loyalty` l
WHERE DATE(l.`date_add`) >= "'.$from.'"
AND DATE(l.`date_add`) <= "'.$to.'"
ORDER BY `nationality`
');
if($results) {
$row_definition = array(
'id_customer' => 'Client ID',
'nationality' => 'Nationalité',
'discount' => 'Bon de réduction',
'credit' => 'Valeur crédit',
'date_generated' => 'Date de génération crédit',
'date_used_in_period' => 'Date utilisation (dans la période)',
'date_used' => 'Date utilisation',
);
header("Content-Type: text/csv; charset=UTF-8");
header("Content-Disposition: attachment;filename=export-credit-".date('dmYHi').".csv;");
$this->exportCsv($results, $row_definition);
die();
} else {
HelperFormBootstrap::displayWarning($this->l('Aucun résultat pour cette période'));
}
}
}elseif(Tools::isSubmit('submitOrderPdf')){
if(isset($_FILES['csvfile']) && $_FILES['csvfile']['name'] != '') {
$f = fopen($_FILES['csvfile']['tmp_name'], 'r');
fgetcsv($f, 0, ';');
$i = 1;
$orders = array();
while($line = fgetcsv($f, 0, ';')) {
$i++;
$orders[] = (int) $line[0];
}
if(!empty($orders)) {
session_start();
$_SESSION['id_orders'] = $orders;
Tools::redirectAdmin('pdf.php?privatesalesManyOrders&gift=1&token='.$this->token);
//PDF::multipleInvoices($orders, false, true, false, true);
}
}
}
}
public function display() {
global $cookie, $currentIndex;
$base_link = $currentIndex . '&token='.Tools::getAdminTokenLite('AdminAntConfigurations');
$form = '';
$id_sale_options = array();
$id_category_options = array();
foreach(Db::getInstance()->ExecuteS('
SELECT p.`id_sale`, c.`name`, c.`id_category`
FROM `'._DB_PREFIX_.'privatesale` p
LEFT JOIN `'._DB_PREFIX_.'category_lang` c ON (c.`id_category` = p.`id_category`)
WHERE c.`id_lang` = '.$cookie->id_lang.'
AND p.`date_start` > "2017-01-01 00:00:00"
ORDER BY p.`id_sale` DESC
LIMIT 1200
') as $row) {
$extrafields = Category::getSalesInfos(array((int) $row['id_category']));
$id_sale_options[] = array(
'label' => (int) $row['id_sale'].' - '.$row['name'].(empty($extrafields[(int) $row['id_category']]['sales'][1])?'':' - '.$extrafields[(int) $row['id_category']]['sales'][1]) ,
'value' => (int) $row['id_sale']
);
$id_category_options[] = array(
'label' => (int) $row['id_sale'].' (#'.(int) $row['id_category'].') - '.$row['name'].(empty($extrafields[(int) $row['id_category']]['sales'][1])?'':' - '.$extrafields[(int) $row['id_category']]['sales'][1]) ,
'value' => (int) $row['id_category']
);
}
$helperForm = new HelperFormBootstrap();
$helperForm->_select2 = true;
$helperForm->_inputMask = true;
$form .= $helperForm->renderStyle();
$form .= '