This commit is contained in:
Michael RICOIS 2017-10-13 12:29:36 +02:00
parent fc84b51f94
commit 2e786a3d2c
3 changed files with 29 additions and 19 deletions

View File

@ -7,10 +7,7 @@ class Export
protected $path;
public function __construct()
{
}
public function __construct(){}
public function setDateStart($date)
{
@ -26,14 +23,14 @@ class Export
{
$sql = "SELECT o.id_order, o.id_customer, od.id_configurator,
a.alias, CONCAT_WS(' ', a.lastname, a.firstname) AS customerName,
'R' AS addressType, a.address1, a.address2, a.other, IF(a.phone_mobile!='', CAST(a.phone_mobile AS CHAR), CAST(a.phone AS CHAR)) AS phone,
'R' AS addressType, a.address1, a.address2, a.other, CAST(IF(a.phone_mobile!='', a.phone_mobile, a.phone) AS CHAR) AS phone,
CAST(a.postcode AS CHAR) AS postcode, a.city, o.payment, o.total_shipping_tax_incl, DATE_FORMAT(o.invoice_date, '%d/%m/%Y') AS invoice_date, o.delivery_date, o.date_add
FROM `"._DB_PREFIX_."order_detail` od
LEFT JOIN `"._DB_PREFIX_."orders` o ON (o.id_order = od.id_order)
LEFT JOIN `"._DB_PREFIX_."customer` c ON (c.id_customer = o.id_customer)
LEFT JOIN `"._DB_PREFIX_."address` a ON (a.id_address = o.id_address_invoice)
LEFT JOIN `"._DB_PREFIX_."country_lang` cl ON (cl.id_country = a.id_country AND cl.id_lang = 1)
WHERE o.id_order = 42 AND o.id_address_delivery = a.id_address /*AND o.date_add > '".$this->dateStart."' AND o.date_add < '".$this->dateEnd."'*/";
WHERE o.id_address_delivery = a.id_address AND o.date_add > '".$this->dateStart."' AND o.date_add < '".$this->dateEnd."'";
$result = Db::getInstance()->executeS($sql);
if (count($result) > 0) {
@ -124,13 +121,14 @@ class Export
public function customer()
{
$sql = "SELECT o.id_order, od.id_configurator,
gl.name AS gender, c.id_customer, c.firstname, c.lastname, c.email, a.address1, a.address2, a.postcode, a.city, a.phone, a.phone_mobile
gl.name AS gender, c.id_customer, c.firstname, c.lastname, c.email, a.address1, a.address2, a.postcode, a.city,
CAST(a.phone AS CHAR) AS phone, CAST(a.phone_mobile AS CHAR) AS phone_mobile
FROM `"._DB_PREFIX_."order_detail` od
LEFT JOIN `"._DB_PREFIX_."orders` o ON (o.id_order = od.id_order)
LEFT JOIN `"._DB_PREFIX_."customer` c ON (c.id_customer = o.id_customer)
LEFT JOIN `"._DB_PREFIX_."address` a ON (a.id_address = o.id_address_invoice)
LEFT JOIN `"._DB_PREFIX_."gender_lang` gl ON (gl.id_gender = c.id_gender AND gl.id_lang = 1)
WHERE o.id_order = 42/*o.date_add > '".$this->dateStart."' AND o.date_add < '".$this->dateEnd."'*/
WHERE o.date_add > '".$this->dateStart."' AND o.date_add < '".$this->dateEnd."'
ORDER BY a.date_add ASC";
$result = Db::getInstance()->executeS($sql);
@ -221,7 +219,7 @@ class Export
$sql = "SELECT o.id_order, od.id_configurator, od.product_id, od.product_attribute_id, od.product_name, od.product_reference
FROM "._DB_PREFIX_."order_detail od
LEFT JOIN "._DB_PREFIX_."orders o ON (o.id_order = od.id_order)
WHERE o.id_order = 42/*o.date_add > '".$this->dateStart."' AND o.date_add < '".$this->dateEnd."'*/";
WHERE o.date_add > '".$this->dateStart."' AND o.date_add < '".$this->dateEnd."'";
$result = Db::getInstance()->executeS($sql);
if (count($result) > 0) {
foreach ($result as $k => $p) {
@ -286,7 +284,10 @@ class Export
$fields[] = $k;
}
}
fputcsv($fp, $fields, ';', '"');
$fields = array_map(array($this ,'encodeStr'), $fields);
//fputcsv($fp, $fields, ';', '"');
fwrite($fp, join(';', $fields)."\n");
// Line
foreach ($data as $l) {
@ -298,10 +299,23 @@ class Export
$fields[] = '';
}
}
fputcsv($fp, $fields, ';', '"');
$fields = array_map(array($this ,'encodeStr'), $fields);
//fputcsv($fp, $fields, ';', '"');
fwrite($fp, join(';', $fields)."\n");
}
fclose($fp);
}
protected function encodeStr($value)
{
///remove any ESCAPED double quotes within string.
$value = str_replace('\\"','"',$value);
//then force escape these same double quotes And Any UNESCAPED Ones.
$value = str_replace('"','\"',$value);
//force wrap value in quotes and return
return '"'.$value.'"';
}
}

View File

@ -10,7 +10,6 @@ class ExportOrder extends ObjectModel
'primary' => 'id_exportorder',
'multilang' => false,
'fields' => array(
'id_exportorder' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'date_start' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true),
'date_end' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true),
),

View File

@ -79,6 +79,7 @@ class AdminAntExportOrderController extends ModuleAdminController
exit;
}
// Action
if ($this->display == 'generate') {
$date_start = Tools::getValue('date_start').' 00:00:00';
$date_end = Tools::getValue('date_end').' 23:59:59';
@ -106,7 +107,6 @@ class AdminAntExportOrderController extends ModuleAdminController
$export->invoiceLine();
$this->id = $insertId;
$this->id_exportorder = $insertId;
} else {
$this->errors[] = Tools::displayError('Cannot generate files from '.$date_start.' to '.$date_end);
return;
@ -114,12 +114,9 @@ class AdminAntExportOrderController extends ModuleAdminController
}
$this->display = 'view';
}
if ($this->display == 'regenerate') {
} elseif ($this->display == 'regenerate') {
$id = Tools::getValue('id_exportorder');
$this->id = $id;
$this->id_exportorder = $id;
$sql = 'SELECT `date_start`, `date_end` FROM `'._DB_PREFIX_.$this->table.'` WHERE `id_exportorder`='.$id;
$result = Db::getInstance()->getRow($sql);
@ -132,9 +129,9 @@ class AdminAntExportOrderController extends ModuleAdminController
$export->invoiceLine();
$this->display = 'view';
} else {
parent::postProcess();
}
parent::postProcess();
}
public function initContent()