Matching cols

This commit is contained in:
Michael RICOIS 2017-10-09 14:51:19 +02:00
parent abbd66ea98
commit 5fde4ac4a9
3 changed files with 322 additions and 8 deletions

View File

@ -3,6 +3,8 @@ if (!defined('_PS_VERSION_')) {
exit;
}
require_once dirname(__FILE__).'/classes/Export.php';
class AntExportOrder extends Module
{
public function __construct()
@ -29,6 +31,24 @@ class AntExportOrder extends Module
return false;
}
//Database
$sql = array(
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."exportorder` (
`id_exportorder` int(11) unsigned NOT NULL AUTO_INCREMENT,
`date_start` datetime NOT NULL,
`date_end` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'
PRIMARY KEY (`id_exportorder`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8",
);
if (count($sql) > 0) {
foreach($sql as $s) {
if (!Db::getInstance()->execute($s)) {
return false;
}
}
}
// Menu
if (!$this->installTab('AdminOrders', 'AdminAntExportOrder', 'Export Orders')) {
return false;

View File

@ -7,7 +7,7 @@ class Export
Facture : Livraison ?
id_order, id_customer, company, lastname + firstname, address1, address2, other, phone_mobile|phone, postcode, city,
SELECT o.id_order, o.id_customer, a.company, CONCAT_WS(' ', a.lastname, a.firstname), a.address1, a.address2, a.other,
SELECT o.id_order, o.id_customer, a.company, CONCAT_WS(' ', a.lastname, a.firstname) AS customerName, a.address1, a.address2, a.other,
IF(a.phone_mobile!='', a.phone_mobile, a.phone) AS phone, a.postcode, a.city, o.date_add
FROM ps_address a, ps_orders o
WHERE o.id_address_delivery = a.id_address AND o.date_add > AAAA-MM-JJ
@ -15,25 +15,159 @@ WHERE o.id_address_delivery = a.id_address AND o.date_add > AAAA-MM-JJ
Client : Adresse Facturation
id_client,
SELECT *
FROM ps_address a, ps_customer c
WHERE c.id_customer = a.id_customer
SELECT o.id_order, c.id_gender, c.firstname, c.lastname, c.email, a.address1, a.address2, a.postcode, a.city, a.phone, a.phone_mobile
FROM ps_orders o
LEFT JOIN ps_customer c ON (c.id_customer = o.id_customer)
LEFT JOIN ps_address a ON (a.id_address = o.id_address_invoice)
WHERE o.date_add >
ORDER BY a.date_add ASC
Facture Ligne :
id_order,
SELECT o.id_order, od.product_name, od.product_reference, al.name AS attribute_name, od.configurator_desc, od.product_attribute_id
SELECT o.id_order, od.product_name, od.product_reference, al.name AS attribute_name, od.id_configurator, od.configurator_desc,
od.product_attribute_id
FROM ps_order_detail od
LEFT JOIN ps_orders o ON (od.id_order = o.id_order)
LEFT JOIN ps_attribute_lang al ON (al.id_attribute = od.product_attribute_id AND al.id_lang = 1)
WHERE
WHERE o.date_add > AAAA-MM-JJ
Pour chaque ligne / produit => récupérer la configuration
getOptProductSelected
Ajouter une table exportorder
id, date_start, date_end
*/
protected $dateStart;
protected $dateEnd;
protected $path;
public function __construct()
{
}
public function invoice()
{
$sql = "SELECT o.id_order, o.id_customer, a.company, CONCAT_WS(' ', a.lastname, a.firstname) AS customerName,
a.address1, a.address2, a.other, IF(a.phone_mobile!='', a.phone_mobile, a.phone) AS phone,
a.postcode, a.city, o.payment, o.total_shipping_tax_incl, o.invoice_date, o.delivery_date, o.date_add
FROM ps_address a, ps_orders o
WHERE o.id_address_delivery = a.id_address /*AND o.date_add > AAAA-MM-JJ*/";
$result = Db::getInstance()->executeS($sql);
$header = array(
0 => array('label' => 'ID_fact', 'col' => 'id_order'),
1 => array('label' => 'no_client', 'col' => 'id_customer'),
2 => array('label' => 'Nom_livr', 'col' => 'company'),
3 => array('label' => 'contact_livr', 'col' => 'customerName'),
4 => array('label' => 'Adresse_livr_ligne1', 'col' => 'address1'),
5 => array('label' => 'Adresse_livr_ligne2', 'col' => 'address2'),
6 => array('label' => 'Adresse_livr_ligne3', 'col' => 'other'),
7 => array('label' => 'instruction_livr', 'col' => ''),
8 => array('label' => 'tel_livr', 'col' => 'phone'),
9 => array('label' => 'CP_livr', 'col' => 'postcode'),
10 => array('label' => 'Ville_livr', 'col' => 'city'),
11 => array('label' => 'code_pays_livr', 'col' => ''),
12 => array('label' => 'Date_livraison', 'col' => 'delivery_date'),
13 => array('label' => 'Date_facturation', 'col' => 'invoice_date'),
14 => array('label' => 'type papier', 'col' => ''),
15 => array('label' => 'finition papier', 'col' => ''),
16 => array('label' => 'Déduction_échantillon', 'col' => ''),
17 => array('label' => 'mode paiement', 'col' => 'payment'),
18 => array('label' => 'Reference BC', 'col' => ''),
19 => array('label' => 'Détail paiement', 'col' => ''),
20 => array('label' => '% reduc', 'col' => ''),
21 => array('label' => 'Cause_%_reduc', 'col' => ''),
22 => array('label' => 'Frais de port', 'col' => 'total_shipping_tax_incl'),
23 => array('label' => 'Envoi fichiers', 'col' => ''),
24 => array('label' => 'Envoi fichiers DENIS', 'col' => ''),
25 => array('label' => 'no suivi colis', 'col' => ''),
26 => array('label' => 'Emb usine', 'col' => ''),
27 => array('label' => 'Reception LGC', 'col' => ''),
28 => array('label' => 'Date d\'expé', 'col' => ''),
29 => array('label' => 'Reception Btq', 'col' => ''),
30 => array('label' => 'Montant en attente', 'col' => ''),
31 => array('label' => 'Vendeur', 'col' => ''),
32 => array('label' => 'Caisse iso', 'col' => ''),
33 => array('label' => 'Password suivi', 'col' => ''),
34 => array('label' => 'importation_faite', 'col' => ''),
35 => array('label' => 'mail confirmation exp', 'col' => ''),
36 => array('label' => 'mail fact acquit', 'col' => ''),
);
$file = './export/invoice_date.csv';
$this->csv($file, $header, $result);
}
public function customer()
{
$sql = "SELECT o.id_order, c.id_gender, c.firstname, c.lastname, c.email, a.address1, a.address2, a.postcode, a.city, a.phone, a.phone_mobile
FROM ps_orders o
LEFT JOIN ps_customer c ON (c.id_customer = o.id_customer)
LEFT JOIN ps_address a ON (a.id_address = o.id_address_invoice)
/*WHERE o.date_add >*/
ORDER BY a.date_add ASC";
$result = Db::getInstance()->executeS($sql);
$header = array(
0 => array('label' => 'no_client', 'col' => 'id_customer'),
1 => array('label' => 'Civilité', 'col' => 'id_gender'),
0 => array('label' => 'Nom_fact', 'col' => 'id_customer'),
0 => array('label' => 'Nom_fact_bis', 'col' => 'id_customer'),
0 => array('label' => 'Prénom', 'col' => 'id_customer'),
0 => array('label' => 'Adresse_fact_ligne1', 'col' => 'id_customer'),
0 => array('label' => 'Adresse_fact_ligne2', 'col' => 'id_customer'),
0 => array('label' => 'Adresse_fact_ligne3', 'col' => 'id_customer'),
0 => array('label' => 'no_client', 'col' => 'id_customer'),
0 => array('label' => 'no_client', 'col' => 'id_customer'),
);
$file = './export/customer_date.csv';
$this->csv($file, $header, $result);
}
public function invoiceLine()
{
// si id_configurator !=0 => getOptProductSelected Ref, Value
}
protected function csv($file, $header, $data)
{
$fp = fopen($file, 'w');
// Header
$fields = array();
foreach($header as $k => $v) {
if (!empty($v['label'])) {
$fields[] = $v['label'];
} else {
$fields[] = $k;
}
}
fputcsv($fp, $fields, ',', '"');
// Line
foreach ($data as $l) {
$fields = array();
foreach($header as $k => $v) {
if (!empty($v['col'])) {
$fields[] = $l[$v['col']];
} else {
$fields[] = '';
}
}
fputcsv($fp, $fields, ',', '"');
}
fclose($fp);
}
}

View File

@ -1,9 +1,169 @@
<?php
class AdminAntExportOrderController extends ModuleAdminController
{
public function __construct()
{
$this->table = 'exportorder';
$this->className = 'ExportOrder';
$this->lang = false;
// Set fields list
$this->fields_list = array(
'id_exportorder' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 25
),
'date_start' => array(
'title' => $this->l('Start'),
),
'date_end' => array(
'title' => $this->l('End'),
),
);
// Enable bootstrap
$this->bootstrap = true;
// Call of the parent constructor method
parent::__construct();
}
public function initPageHeaderToolbar()
{
$this->page_header_toolbar_btn['new_exportorder'] = array(
'href' => self::$currentIndex.'&new_exportorder&token='.$this->token,
'desc' => $this->l('Generate new export order', null, null, false),
'icon' => 'process-icon-new'
);
parent::initPageHeaderToolbar();
}
public function postProcess()
{
if (Tools::getIsset('new_exportorder')) {
$this->display = 'new';
} elseif (Tools::getIsset('regenerate_exportorder')) {
$this->display = 'regenerate';
} elseif (Tools::getIsset('submitAddexportorder')) {
$this->display = 'generate';
}
if ($this->display == 'generate') {
// @todo : Get last date if exist
$export = new Export();
$export->invoice();
echo "generate";
exit;
}
if ($this->display == 'regenerate') {
// @todo : Get date
echo "regenerate";
exit;
}
parent::postProcess();
}
public function initContent()
{
$this->initPageHeaderToolbar();
if ($this->display == 'new') {
$this->content = $this->renderForm();
} else {
parent::initContent();
}
$this->context->smarty->assign(array(
'table' => $this->table,
'current' => self::$currentIndex,
'token' => $this->token,
'content' => $this->content,
'url_post' => self::$currentIndex.'&token='.$this->token,
'show_page_header_toolbar' => $this->show_page_header_toolbar,
'page_header_toolbar_title' => $this->page_header_toolbar_title,
'page_header_toolbar_btn' => $this->page_header_toolbar_btn
));
}
public function renderForm()
{
$this->show_form_cancel_button = true;
$this->fields_form = array(
'legend' => array('title' => $this->l('Add / Edit')),
'input' => array(
array(
'type' => 'text',
'label' => $this->l("Starting date"),
'desc' => $this->l("Starting date"),
'name' => 'date_start',
'required' => true,
'lang' => false
),
array(
'type' => 'text',
'label' => $this->l("Ending date"),
'desc' => $this->l("Ending date"),
'name' => 'date_end',
'required' => true,
'lang' => false
),
),
'submit' => array(
'title' => $this->l("Generate new export"),
'class' => 'btn btn-default pull-right',
),
);
// @todo : Get last date_end
$this->fields_value['date_start'] = date('Y-m-d H:i:s');
$this->fields_value['date_end'] = date('Y-m-d H:i:s');
return parent::renderForm();
}
public function displayGenerateLink($token = null, $id, $name = null)
{
$tpl = $this->createTemplate('helpers/list/list_action_details.tpl');
if (!array_key_exists('generate', self::$cache_lang)) {
self::$cache_lang['generate'] = $this->l('Re-Generate export', 'Helper');
}
$link = $this->context->link->getAdminLink('AdminAntExportOrder', true);
$tpl->assign(array(
'href' => $link.'&id_exportorder='.$id.'&regenerate_exportorder',
'action' => self::$cache_lang['generate'],
'id' => $id
));
return $tpl->fetch();
}
public function renderList()
{
$this->_orderBy = 'date_start';
$this->_orderWay = 'DESC';
$this->addRowAction('view'); // View Files
$this->addRowAction('generate'); // Regenerate
return parent::renderList();
}
public function renderView()
{
// Display file
}
}