Merge branch 'ticket-12643-ExportLoyalty' into develop

This commit is contained in:
Marion Muszynski 2017-02-28 12:55:54 +01:00
commit c476007dc6

View File

@ -172,7 +172,64 @@ class AdminAntConfigurations extends AdminTab
HelperFormBootstrap::displayWarning($this->l('Aucun résultat trouvé'));
}
} elseif (Tools::isSubmit('submitExportLoyalty')){
HelperFormBootstrap::displayWarning($this->l('Outils non disponible pour le moment !'));
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`,
IFNULL(l.`id_discount`,"Non transforme") 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',
'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'));
}
}
}
}