adjusting extract
This commit is contained in:
parent
08a2023fb8
commit
b6e13fc8c8
@ -200,27 +200,32 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
$from = Tools::getValue('date_from');
|
||||
$to = Tools::getValue('date_to');
|
||||
$philea_sales = array();
|
||||
foreach (Db::getInstance()->executeS('
|
||||
foreach (Db::getInstance()->ExecuteS('
|
||||
SELECT `id_sale`
|
||||
FROM `' . _DB_PREFIX_ . 'philea_sync`
|
||||
FROM `'._DB_PREFIX_.'philea_sync`
|
||||
') as $row) {
|
||||
if(isset($philea_sales[(int)$row['id_sale']])) {
|
||||
if(!isset($philea_sales[(int)$row['id_sale']])) {
|
||||
$philea_sales[(int)$row['id_sale']] = (int)$row['id_sale'];
|
||||
}
|
||||
}
|
||||
$cmd = Db::getInstance()->executeS('
|
||||
SELECT phs.`date_add`, phs.`id_sale`, o.`date_add` as date_cmd
|
||||
FROM `' . _DB_PREFIX_ . 'orders` o
|
||||
$cmd = Db::getInstance()->ExecuteS('
|
||||
SELECT o.`id_order` as order_id, o.`date_add` as date_cmd,os.`name`, c.`id_sale`, IF(phs.`date_add` IS NULL,"NON","OK") as sent, phs.`date_add` as sent_to_philea
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (o.`id_order` = d.`id_order`)
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'philea_sent` phs ON (o.`id_order` = phs.`id_order`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_state_current` osc ON (o.`id_order` = osc.`id_order`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` os ON (osc.`id_order_state` = os.`id_order_state` AND os.`id_lang`=2)
|
||||
LEFT JOIN `'._DB_PREFIX_.'philea_sent` phs ON (o.`id_order` = phs.`id_order`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON (d.`product_id` = c.`id_product`)
|
||||
WHERE o.`date_add` >= "' .$from. ' 00:00:00"
|
||||
AND o.`date_add` <= "' .$to. ' 23:59:59"
|
||||
WHERE o.`date_add` >= "'.$from.' 00:00:00"
|
||||
AND o.`date_add` <= "'.$to.' 23:59:59"
|
||||
AND c.`id_sale` IN ('.implode(',',$philea_sales).')
|
||||
GROUP BY o.id_order
|
||||
');
|
||||
if ($cmd){
|
||||
echo '<pre>';var_dump($cmd);echo '</pre>';die();
|
||||
//$this->exportCMDcsv($cmd)
|
||||
header("Content-Type: text/csv; charset=UTF-8");
|
||||
header("Content-Disposition: attachment;filename=export-".date('dmYHi').".csv;");
|
||||
$this->exportCmdCsv($cmd);
|
||||
die();
|
||||
}
|
||||
else{
|
||||
echo '<p class="error">'.$this->l('Pas de commandes trouvées pour cette période.').'</p><br />';
|
||||
@ -228,6 +233,36 @@ class AdminPhileaMagistor extends AdminTab {
|
||||
}
|
||||
}
|
||||
|
||||
public function exportCmdCsv($items){
|
||||
$row_definition = array(
|
||||
'order_id' => 'Commande',
|
||||
'date_cmd' => 'Date',
|
||||
'name' => 'Statut',
|
||||
'id_sale' => 'Vente',
|
||||
'sent' => 'Envoyee a Philea',
|
||||
'sent_to_philea' => 'Date envoi',
|
||||
);
|
||||
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 exportCsv($id_sale, $filename){
|
||||
|
||||
$sql = '
|
||||
|
Loading…
Reference in New Issue
Block a user