bebeboutik/modules/ant_configurations/AdminAntConfigurations.php
Marion Muszynski 3a9f7ef77c part 2 of inte
2017-11-13 17:13:07 +01:00

768 lines
42 KiB
PHP

<?php
if(!defined('_PS_VERSION_')) {
exit;
}
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
require_once(PS_ADMIN_DIR . '/helpers/HelperForm.php');
require_once(PS_ADMIN_DIR . '/helpers/HelperList.php');
class AdminAntConfigurations extends AdminTab
{
public function postProcess() {
global $cookie;
if(Tools::isSubmit('submitUpdateConfigurations')) {
Configuration::updateValue('ANT_BOOTSTRAP_TPL', Tools::getValue('bootstrap_tpl'));
Configuration::updateValue('ANT_CARRIER_DROP', Tools::getValue('carrier_dropshipping'));
Configuration::updateValue('ANT_CARRIER_DOM', Tools::getValue('carrier_domicile'));
Configuration::updateValue('ANT_CARRIERS_SOCOL', Tools::getValue('carriers_socol'));
Configuration::updateValue('ANT_CARRIERS_MR', Tools::getValue('carriers_mr'));
Configuration::updateValue('ANT_CARRIERS_OOH', Tools::getValue('carriers_ooh'));
Configuration::updateValue('ANT_CARRIERS_SPECIAL', Tools::getValue('carriers_special'));
Configuration::updateValue('ANT_BESTSALE_EXCEPTION', Tools::getValue('sales_exception'));
HelperFormBootstrap::displaySuccess($this->l('Configurations mises à jour'));
} elseif(Tools::isSubmit('submitCleanBestSellerCache')) {
$filenames = array(
_PS_ROOT_DIR_.'/modules/blockbestsellers/blockbestsellers_2.txt',
_PS_ROOT_DIR_.'/modules/blockbestsellers/blockbestsellers_home_2.txt',
_PS_ROOT_DIR_.'/modules/blockbestsellers/blockbestsellers_cart_2.txt',
_PS_ROOT_DIR_.'/modules/blockbestsellers/blockbestsellers_3.txt',
_PS_ROOT_DIR_.'/modules/blockbestsellers/blockbestsellers_home_3.txt',
_PS_ROOT_DIR_.'/modules/blockbestsellers/blockbestsellers_cart_3.txt'
);
foreach ($filenames as $file) {
if(file_exists($file)){
unlink($file);
}
}
HelperFormBootstrap::displaySuccess($this->l('Cache Meilleures ventes vidé !'));
} 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).') :<br />'.wordwrap($result, 100, "<br />"));
} 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 = '<style type="text/css">
.path_bar {
background-color: #F1F1F1;
border: 1px solid #565485;
}
h2 {
color: #565485;
}
fieldset {
background: #F1F1F1;
border: 1px solid #565485;
}
legend {
background: #565485;
background: rgba(86,84,133,0.9);
border: 1px solid #565485;
color: #fff;
}
input[type="text"], input[type="password"],
input[type="file"], textarea, select {
border: 1px solid #565485;
}
.button {
background-color: rgba(86,84,133,0.7);
border: 1px solid #565485;
border-left: 1px solid rgba(86,84,133,0.6);
border-top: 1px solid rgba(86,84,133,0.6);
color: rgba(255,255,255,0.9);
padding: 3px;
}
.button:hover {
background-color: #565485;
border: 1px solid rgba(86,84,133,0.6);
border-left: 1px solid #565485;
border-top: 1px solid #565485;
color: #fff;
padding: 3px;
}
.button:focus{
background-color: rgba(86,84,133,0.6);
}
.control-label {
padding: 0;
}
.heading-title{
margin: 5px 0 20px;
display: block;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
color: #504d8b;
}
</style>';
$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;
$helperForm->_inputSwitch = true;
$form .= $helperForm->renderStyle();
$form .= '
<div class="row">
<div class="col-md-12">
<div class="panel">
<h2 class="heading-title"><span class="anticon anticon-cog"></span> '.$this->l('Outils utiles').'</h2>
<ul class="nav nav-tabs nav-justified">
<li role="presentation" class="'.(!Tools::getIsset('tab-pan') || Tools::getValue('tab-pan') == 'categories'?'active':'').'">
<a href="#categories" aria-controls="categories" role="tab" data-toggle="tab"><span class="text-rose anticon anticon-tree"></span> '.$this->l('Association Catégorie/vente').'</a>
</li>
<li role="presentation" class="'.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'products'?'active':'').'">
<a href="#products" aria-controls="prices" role="tab" data-toggle="tab"><span class="text-rose anticon anticon-tree"></span> '.$this->l('Association Produit/vente').'</a>
</li>
<li role="presentation" class="'.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'discounts'?'active':'').'">
<a href="#discounts" aria-controls="discount" role="tab" data-toggle="tab"><span class="text-rose anticon anticon-price-tags"></span> '.$this->l('Suivi bons réductions').'</a>
</li>
<li role="presentation" class="'.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'loyalties'?'active':'').'">
<a href="#loyalties" aria-controls="loyalty" role="tab" data-toggle="tab"><span class="text-rose anticon anticon-star-full"></span> '.$this->l('Suivi crédits fidélités').'</a>
</li>
<li role="presentation" class="'.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'invoices'?'active':'').'">
<a href="#invoices" aria-controls="loyalty" role="tab" data-toggle="tab"><span class="text-rose anticon anticon-file-pdf"></span> '.$this->l('Factures').'</a>
</li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane '.(!Tools::getIsset('tab-pan') || Tools::getValue('tab-pan') == 'categories'?'active':'').'" id="categories">
<div class="panel-content">
<h3 class="">'.$this->l('Association Catégories/Ventes').'</h3>
<br>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&tab-pan=categories" method="post" enctype="multipart/form-data">
<div class="col-md-6 col-md-offset-3">';
$input = $input = array(
'type' => 'select2',
'label' => $this->l('Vente à associer :'),
'label-class' => 'col-md-12',
'input-class' => 'col-md-12',
'select-class' => 'col-md-12',
'name' => 'id_sale',
'options' => $id_sale_options,
);
$form .= $helperForm->generateInput($input).
'</div>
<div class="clearfix"></div>
<div class="ln_solid"></div>
<div class="form-group text-right">
<button type="submit" class="btn btn-primary" name="submitCategorySaleCache">'.$this->l('Mettre à jour l\'association').'</button>
</div>
</form>
</div>
</div>
<div role="tabpanel" class="tab-pane '.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'products'?'active':'').'" id="products">
<div class="panel-content">
<h3 class="">'.$this->l('Association Produit/Ventes').'</h3>
<br>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&tab-pan=products" method="post" enctype="multipart/form-data">
<div class="col-md-6 col-md-offset-3">
<p class="text-center">'.$this->l('Permet d\'associer les produits aux ventes lorsque le cron n\'est pas encore passé.').'</p>
<p class="text-center">'.$this->l('Passage du cron toutes les 3h : 6h12, 9H12, 12h12 ...').'</p>
</div>
<div class="clearfix"></div>
<div class="ln_solid"></div>
<div class="form-group text-right">
<button type="submit" class="btn btn-primary" name="submitProductSaleCache">'.$this->l('Mettre à jour l\'association').'</button>
</div>
</form>
</div>
</div>
<div role="tabpanel" class="tab-pane '.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'discounts'?'active':'').'" id="discounts">
<div class="panel-content">
<h3 class="">'.$this->l('Suivi Code Promo').'</h3>
<br>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&tab-pan=discounts" method="post" enctype="multipart/form-data">
<div class="col-md-6 col-md-offset-3">
<p class="text-center">'.$this->l('Export des codes promos générés et de leur utilisations.').'
<br>'.$this->l('Préférer de courtes périodes (se base sur la date de génération du bon).').'</p>';
$input = array(
'type' => 'simpleDate',
'period' => true,
'class-from' => 'col-md-6',
'class-to' => 'col-md-6',
'label' => 'De :',
'label-to' => 'A :',
'id' => 'date_from',
'id-to' => 'date_to',
'name' => 'date_from',
'name-to' => 'date_to',
'before' => '<span class="glyphicon glyphicon-calendar"></span>',
'before-to' => '<span class="glyphicon glyphicon-calendar"></span>',
);
$form .= $helperForm->generateInput($input).
'</div>
<div class="clearfix"></div>
<div class="ln_solid"></div>
<div class="form-group text-right">
<button type="submit" class="btn btn-primary" name="submitExportDiscount">'.$this->l('Exporter Suivi Code promo').'</button>
</div>
</form>
</div>
</div>
<div role="tabpanel" class="tab-pane '.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'loyalties'?'active':'').'" id="loyalties">
<div class="panel-content">
<h3 class="">'.$this->l('Suivi Crédit Fidélité').'</h3>
<br>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&tab-pan=loyalties" method="post" enctype="multipart/form-data">
<div class="col-md-6 col-md-offset-3">
<p class="text-center">'.$this->l('Choisir de préférence des plages d\'1 mois').'
<br>'.$this->l('(Les dates renseignées sont comprises dans la période demandée)').'</p>';
$input = array(
'type' => 'simpleDate',
'period' => true,
'class-from' => 'col-md-6',
'class-to' => 'col-md-6',
'label' => 'De :',
'label-to' => 'A :',
'id' => 'date_from_2',
'id-to' => 'date_to_2',
'name' => 'date_from',
'name-to' => 'date_to',
'before' => '<span class="glyphicon glyphicon-calendar"></span>',
'before-to' => '<span class="glyphicon glyphicon-calendar"></span>',
);
$form .= $helperForm->generateInput($input).
'</div>
<div class="clearfix"></div>
<div class="ln_solid"></div>
<div class="form-group text-right">
<button type="submit" class="btn btn-primary" name="submitExportLoyalty">'.$this->l('Exporter Crédits fidélités').'</button>
</div>
</form>
</div>
</div>
<div role="tabpanel" class="tab-pane '.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'invoices'?'active':'').'" id="invoices">
<div class="panel-content">
<h3 class="">'.$this->l('Générer un PDF de plusieurs commandes').'</h3>
<br>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&tab-pan=invoices" method="post" enctype="multipart/form-data">
<div class="col-md-6 col-md-offset-4">';
$help = '<br>
<p class="help-block">'.$this->l('Format: id_order').'</p>
<p class="help-block">'.$this->l('The subsequent columns and the first line are ignored.').'</p>
';
$input = array(
'type' => 'file',
'label' => $this->l('File:'),
'name' => 'csvfile',
'html' => $help
);
$form .= $helperForm->generateInput($input);
$form .= '
</div>
<div class="clearfix"></div>
<div class="ln_solid"></div>
<div class="form-group text-right">
<button type="submit" class="btn btn-primary" name="submitOrderPdf">'.$this->l('Générer PDF').'</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>';
if($cookie->id_employee == 1) {
$nb_credits = $this->getNbOrderToUpdate();
$helperForm->_forms[] = array(
'action' => $base_link,
'title' => '<img src="../img/admin/logo_antadis.jpg" width="30px"/> '.$this->l('Section Antadis'),
'class' => 'form-horizontal',
'class_div' => 'col-md-12',
'sections' => array(
array(
'class' => 'col-md-6',
'title' => $this->l('Actions diverses'),
'inputs' => array(
array(
'type' => 'submit',
'class' => 'btn-default',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'name' => 'submitUpdateLoyaltyOrders',
'label' => $this->l('Credit fidélité ').($nb_credits>0?'('.$nb_credits.')':'').' : ',
'value' => $this->l('Mettre à jour'),
),
array(
'type' => 'submit',
'class' => 'btn-default',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'name' => 'submitCleanBestSellerCache',
'label' => $this->l('Cache Meilleures ventes :'),
'value' => $this->l('Vider le cache'),
),
array(
'type' => 'switch',
'name' => 'bootstrap_tpl',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Bootstrap TPL (BO) :'),
'default' => Configuration::get('ANT_BOOTSTRAP_TPL'),
'checked' => Configuration::get('ANT_BOOTSTRAP_TPL'),
),
array(
'type' => 'simpleText',
'name' => 'carrier_dropshipping',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Transporteur Dropshipping :'),
'default' => Configuration::get('ANT_CARRIER_DROP')
),
array(
'type' => 'simpleText',
'name' => 'carrier_domicile',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Transporteur domicile :'),
'default' => Configuration::get('ANT_CARRIER_DOM')
),
array(
'type' => 'simpleText',
'name' => 'carriers_socol',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Transporteur socol :'),
'default' => Configuration::get('ANT_CARRIERS_SOCOL')
),
array(
'type' => 'simpleText',
'name' => 'carriers_mr',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Transporteur MR :'),
'default' => Configuration::get('ANT_CARRIERS_MR')
),
array(
'type' => 'simpleText',
'name' => 'carriers_ooh',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Transporteur OOH :'),
'default' => Configuration::get('ANT_CARRIERS_OOH')
),
array(
'type' => 'simpleText',
'name' => 'carriers_special',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Transporteur speciaux :'),
'default' => Configuration::get('ANT_CARRIERS_SPECIAL')
),
array(
'type' => 'simpleText',
'name' => 'sales_exception',
'label-class' => 'col-md-6',
'input-class' => 'col-md-4',
'label' => $this->l('Meilleures ventes exception :'),
'default' => Configuration::get('ANT_BESTSALE_EXCEPTION')
),
),
),
array(
'class' => 'col-md-6',
'title' => $this->l('Mettre à jour PS Cache'),
'inputs' => array(
array(
'label' => $this->l('PS Cache : '),
'type' => 'select2',
'class-select' => '',
'name' => 'id_category',
'options' => $id_category_options,
),
),
'actions' => array(
array(
'type' => 'submit',
'class' => 'btn-default',
'name' => 'submitShowProductCacheSale',
'value' => $this->l('Voir'),
),
array(
'type' => 'submit',
'class' => 'btn-primary',
'name' => 'submitUpdateCacheSale',
'value' => $this->l('Ré-Associer'),
),
),
'actions-class' => 'text-right',
),
),
'actions' => array(
array(
'type' => 'submit',
'class' => 'btn-primary',
'name' => 'submitUpdateConfigurations',
'value' => $this->l('Mettre à jour les configurations')
)
),
'actions-class' => 'text-center',
);
}
$helperForm->_js .= '
<script>
$(document).ready(function() {
$("#date_from").inputmask("9999-99-99");
$("#date_to").inputmask("9999-99-99");
$("#date_from_2").inputmask("9999-99-99");
$("#date_to_2").inputmask("9999-99-99");
$("#id_sale").parent().children(".select2-container").css(\'width\',\'449px\');
});
</script>';
$form .= '<div class="clearfix"></div><div class="row">'.$helperForm->renderForm(false, NULL, NULL, true).'</div>';
$form .= $helperForm->renderScript();
echo $form;
}
public function updateLoyaltyOrders()
{
include_once(_PS_ROOT_DIR_.'/modules/loyalty/LoyaltyStateModule.php');
include_once(_PS_ROOT_DIR_.'/modules/loyalty/LoyaltyModule.php');
$loyaltyStateValidation = new LoyaltyStateModule(LoyaltyStateModule::getValidationId());
$count_orders = 0;
foreach (Db::getInstance()->ExecuteS('
SELECT lo.`id_order`, oh.`id_order_state`
FROM `'._DB_PREFIX_.'loyalty` lo
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = lo.`id_order`)
WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = lo.`id_order` GROUP BY moh.`id_order`)
AND oh.`id_order_state` = 4 AND lo.`id_loyalty_state` NOT IN (2,4)
') as $order) {
if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(LoyaltyModule::getByOrderId((int)$order['id_order'])))) {
continue;
}
if ((int)Configuration::get('PS_LOYALTY_NONE_AWARD') AND $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId()) {
continue;
}
if ((int)$order['id_order_state'] == $loyaltyStateValidation->id_order_state)
{
$loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId();
if ((float)($loyalty->discount_value) == 0) {
$loyalty->discount_value = LoyaltyModule::getOrderDiscountValue($order);
}
}
if($loyalty->save()) {
$count_orders++;
}
}
return $count_orders;
}
public function getNbOrderToUpdate()
{
return Db::getInstance()->getValue('
SELECT COUNT(lo.`id_order`)
FROM `'._DB_PREFIX_.'loyalty` lo
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = lo.`id_order`)
WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = lo.`id_order` GROUP BY moh.`id_order`)
AND oh.`id_order_state` = 4 AND lo.`id_loyalty_state` NOT IN (2,4)
');
}
public function exportCsv($items, $row_definition)
{
ob_clean();
$fp = fopen('php://output', 'w');
$delim = ';';
// first row
$data=array();
foreach ($row_definition as $col_name ) {
$data[]=Tools::htmlentitiesDecodeUTF8($col_name);
}
fputcsv ($fp,$data,$delim);
foreach ($items as $item) {
$data = array();
foreach ($row_definition as $key => $col) {
$data[] = (isset($item[$key]) ? $item[$key] : '');
}
fputcsv ($fp,array_map('utf8_decode',array_values($data)),$delim);
}
fclose($fp);
}
public function cleanMenuCache()
{
$id_langs = array(2,3);
foreach ($id_langs as $key => $id_lang) {
$filename = _PS_ROOT_DIR_.'/modules/privatesales_family_menu/menu_'.$id_lang.'.txt';
if(file_exists($filename)) {
unlink($filename);
}
}
}
}